Nov 21, 2009

How To Find And Test Imagemagick Using Php

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

How To Find And Test Imagemagick Using Php

docduke
One of the powerful graphics manipulation programs that AstaHost provides is ImageMagick. AstaHost recognizes its importance by placing a reference to it on its home page in the right column:

Our Free Web Hosting offer :-
  • ...
  • * ImageMagick Support
I have not seen ImageMagick mentioned in any other free, or nearly free, Web service. This is one of the things that attracted me to AstaHost. ImageMagick is very powerful. As its website describes its capabilities:
  • ImageMagick® is a software suite to create, edit, and compose bitmap images.
  • It can read, convert and write images in a variety of formats (over 100).
  • ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you may freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems.
Personally, I am interested in it because it is a necessary tool in MediaWiki. If one wishes to typeset mathematical equations in MediaWiki (as is done in Wikipedia), ImageMagick is a required component of the extension that provides this capability.

A while ago, I had trouble finding it on gamma.xisto.com. This tutorial shows how to test for it, and verify that it is functional. Since the primary focus of AstaHost is web hosting, the tutorial is in PHP. This illustrates how ImageMagick can be used in any website that uses PHP scripts.

Here is a PHP program to test for the presence of ImageMagick, and print out its version number.
CODE
<html> <head> <title>Test for ImageMagick</title> </head>
<body> <?
function alist ($array) {  //This function prints a text array as an html list.
  $alist = "<ul>";
  for ($i = 0; $i < sizeof($array); $i++) {
    $alist .= "<li>$array[$i]";
  }
  $alist .= "</ul>";
  return $alist;
}
exec("convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number.
echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error.
echo alist($out); //Print the output of "convert -version"
//Additional code discussed below goes here.
?> </body> </html>

Create a file in your public_html folder or a subfolder, paste this text into it, and name it something like test4im.php where the ".php" ending is necessary to get the PHP interpreter to process it. Point a browser at this file (e.g. http://[your website]/test4im.php). If you have access to "convert," you will get a return code of 0 plus two or three lines of text, reporting the version and location of ImageMagick. Strictly speaking, you do not need to create the alist function since it is only called once here, but if you wish to test other things, it will save repetitive typing. (This is, after all, a tutorial on PHP.)

There is one more important step to make sure you can use ImageMagick. Almost everything you do with it will involve creating a file. Therefore, you need to be sure you can give it an argument that correctly identifies the location you want, and provides the appropriate permissions. Suppose you want the output in a folder called "temp" in your public_html folder. First you must create the folder and set its permissions. Use cPanel to create a folder "public_html/temp". Use the "permissions" tool to set "temp" to "777" which means anyone (including the "user" that runs an html task) can write to the "temp" folder. Now add the following two lines to your "test4im.php" program, at the location of the next-to-last line above.
CODE
exec("convert logo: /home/[your cPanel name]/public_html/temp/imlogo.gif", $out, $rcode);
echo "Logo return code is $rcode <br>";

The first line creates an ImageMagick logo image and stores it in the "temp" folder. The second prints the return code. Save this modified file and reload the browser page. If you got a version number before, and now get a non-zero return code, you probably didn't create the "temp" folder in the right place, or set its permissions correctly. If you get a return code of 0, examine the "imlogo.gif" file using the "View" tool in the cPanel File Manager. You should see this:
The default logo image is 640x480 pixels. If you want a smaller one, such as the one above, creating it is as simple as:
CODE
convert logo: -resize 25% /home/[your cPanel name]/www/temp/imlogo2.gif

Once you have it running, the Basic Usage page will give you lots of ideas on how to use ImageMagick for your own applications. When you are ready to study the details, the options page will show you how to do much more complex image transformations.

Enjoy! cool.gif

 

 

 


Comment/Reply (w/o sign-up)

TavoxPeru
Thanks a lot docduke, i just follow your tutorial and test your code and every thing works perfectly.

BTW, this is the first time that i use Imagemagick and to be honest it is awesome, i don't know that with it you can do a lot of incredible things with images.

Best regards,

Comment/Reply (w/o sign-up)

yordan
ImageMagick is used by 4gallery photogallery. When you set up your site, it asks you where imagemagick is installed in your server. If not, you have to use gl libraries, which generally use too much memory.

Comment/Reply (w/o sign-up)

actuary
QUOTE(docduke @ Jun 4 2008, 03:20 AM) *
One of the powerful graphics manipulation programs that AstaHost provides is ImageMagick. AstaHost recognizes its importance by placing a reference to it on its home page in the right column:

Our Free Web Hosting offer :-
  • ...
  • * ImageMagick Support
I have not seen ImageMagick mentioned in any other free, or nearly free, Web service. This is one of the things that attracted me to AstaHost. ImageMagick is very powerful. As its website describes its capabilities:
  • ImageMagick® is a software suite to create, edit, and compose bitmap images.
  • It can read, convert and write images in a variety of formats (over 100).
  • ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you may freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems.
Personally, I am interested in it because it is a necessary tool in MediaWiki. If one wishes to typeset mathematical equations in MediaWiki (as is done in Wikipedia), ImageMagick is a required component of the extension that provides this capability.

A while ago, I had trouble finding it on gamma.xisto.com. This tutorial shows how to test for it, and verify that it is functional. Since the primary focus of AstaHost is web hosting, the tutorial is in PHP. This illustrates how ImageMagick can be used in any website that uses PHP scripts.

Here is a PHP program to test for the presence of ImageMagick, and print out its version number.
CODE
<html> <head> <title>Test for ImageMagick</title> </head>
<body> <?
function alist ($array) {  //This function prints a text array as an html list.
  $alist = "<ul>";
  for ($i = 0; $i < sizeof($array); $i++) {
    $alist .= "<li>$array[$i]";
  }
  $alist .= "</ul>";
  return $alist;
}
exec("convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number.
echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error.
echo alist($out); //Print the output of "convert -version"
//Additional code discussed below goes here.
?> </body> </html>

Create a file in your public_html folder or a subfolder, paste this text into it, and name it something like test4im.php where the ".php" ending is necessary to get the PHP interpreter to process it. Point a browser at this file (e.g. http://[your website]/test4im.php). If you have access to "convert," you will get a return code of 0 plus two or three lines of text, reporting the version and location of ImageMagick. Strictly speaking, you do not need to create the alist function since it is only called once here, but if you wish to test other things, it will save repetitive typing. (This is, after all, a tutorial on PHP.)

There is one more important step to make sure you can use ImageMagick. Almost everything you do with it will involve creating a file. Therefore, you need to be sure you can give it an argument that correctly identifies the location you want, and provides the appropriate permissions. Suppose you want the output in a folder called "temp" in your public_html folder. First you must create the folder and set its permissions. Use cPanel to create a folder "public_html/temp". Use the "permissions" tool to set "temp" to "777" which means anyone (including the "user" that runs an html task) can write to the "temp" folder. Now add the following two lines to your "test4im.php" program, at the location of the next-to-last line above.
CODE
exec("convert logo: /home/[your cPanel name]/public_html/temp/imlogo.gif", $out, $rcode);
echo "Logo return code is $rcode <br>";

The first line creates an ImageMagick logo image and stores it in the "temp" folder. The second prints the return code. Save this modified file and reload the browser page. If you got a version number before, and now get a non-zero return code, you probably didn't create the "temp" folder in the right place, or set its permissions correctly. If you get a return code of 0, examine the "imlogo.gif" file using the "View" tool in the cPanel File Manager. You should see this:
The default logo image is 640x480 pixels. If you want a smaller one, such as the one above, creating it is as simple as:
CODE
convert logo: -resize 25% /home/[your cPanel name]/www/temp/imlogo2.gif

Once you have it running, the Basic Usage page will give you lots of ideas on how to use ImageMagick for your own applications. When you are ready to study the details, the options page will show you how to do much more complex image transformations.

Enjoy! cool.gif


Thank you very much for your kindly advice.
But it seemed to me that I can NOT see your last image you pasted.

 

 

 


Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Imagemagick Php


    Looking for test, imagemagick, php

See Also,

*SIMILAR VIDEOS*
Searching Video's for test, imagemagick, php
advertisement



How To Find And Test Imagemagick Using Php

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com