bookmark - How To Find And Test Imagemagick Using Php

How To Find And Test Imagemagick Using Php

 
 Discussion by docduke with 3 Replies.
 Last Update: September 16, 2008, 1:39 am
 
bookmark - How To Find And Test Imagemagick Using Php  
    
free web hosting
 
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 :-

  1. ...
  2. * 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:

  1. ImageMagick® is a software suite to create, edit, and compose bitmap images.
  2. It can read, convert and write images in a variety of formats (over 100).
  3. 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: i256258_imlogo2.gif
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! :)

Wed Jun 4, 2008    Reply    New Discussion   


QUOTE (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 :-

  1. ...
  2. * 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:

  1. ImageMagick® is a software suite to create, edit, and compose bitmap images.
  2. It can read, convert and write images in a variety of formats (over 100).
  3. 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: i256258_imlogo2.gif
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! ;)
Link: view Post: 124048


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

Tue Sep 16, 2008    Reply    New Discussion   

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,

Thu Jun 5, 2008    Reply    New Discussion   

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.

Mon Jun 9, 2008    Reply    New Discussion   


Quickly Post to How To Find And Test Imagemagick Using Php  w/o signup Share Info about How To Find And Test Imagemagick Using Php  using Facebook, Twitter etc. email your friend about How To Find And Test Imagemagick Using Php Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

How To Create A "user Profile" Page. No design (easy to add later if you want).  How To Create A "user Profile" Page. No design (easy to add later if you want). (41) (3) Creating A Php Login Script A thorough look at the process behind it  Creating A Php Login Script A thorough look at the process behind it