×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Third Party Scripts/Modules

Using ImageMagick with PHP by Glowball
Posted: 19 Jul 05 (Edited 13 Aug 06)

Quoting ImageMagick.org, "ImageMagick... is a free software suite to create, edit, and compose bitmap images. It can read, convert and write images in a large variety of formats. Images can be cropped, colors can be changed, various effects can be applied, images can be rotated and combined, and text, lines, polygons, ellipses and BTzier curves can be added to images and stretched and rotated."

It is like the PHP GD Library but much more robust.  It also produces nice thumbnails from JPEG images when the GD Library falls short.

Visit http://www.imagemagick.org for a good overview of ImageMagick.

Go to http://www.cit.gu.edu.au/~anthony/graphics/imagick6/ to get more details about what it does and what you can do with it.

This FAQ will get you started working with ImageMagick for PHP.  First you need to verify with your host that ImageMagick is installed.  Then you need to find out if your PHP installation is as an Apache module or as CGI (phpsuexec).

Step One: Make a .php file for the ImageMagick code.

Step Two: Make a subdirectory where that .php file is that will hold your test image. It needs to be writable (777 permissions) so you can write the new image to it.

Step Three: Put one of the following blocks of code on your PHP page, based on your installation type.

If your server has PHP installed as an Apache module then call ImageMagick like this:

CODE

$test_directory = 'test';
$command = "convert -background lightblue -fill blue -font 'Arial' -pointsize 72 label:'Testing' $test_directory/mytest.gif";
$test_image = system($command, $returnVal);
if ($returnVal > 1) echo "ERROR";
else echo "<img src=\"$test_directory/mytest.gif\">";

If your server has PHP installed as CGI (phpsuexec) then you can't use system(). You also can't run your script from a directory with 777 permissions so don't try that. Try this code:

CODE

$test_directory = 'test';
$path_to_imagemagick = '/usr/bin/convert';
$command = "convert -background lightblue -fill blue -font 'Arial' -pointsize 72 label:'Testing' $test_directory/mytest.gif";
passthru("\"$path_to_imagemagick\" $command", $returnVal);
if ($returnVal > 1) echo "ERROR";
else echo "<img src=\"$test_directory/mytest.gif\">";

Note: if you are creating thumbnails and the -thumbnail command isn't working, try -resize instead (with the same parameters).  Have fun!

Back to PHP FAQ Index
Back to PHP Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close