Our Free Web Hosting offer :-
- ...
- * ImageMagick Support
- 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.
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>
<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>";
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!

