Using ImageMagick (imagick.so) with PHP on Dreamhost

Not very interesting, but this is for future Googlers. It was a frustrating process to dope out.

Installation

I had a lot of trouble compiling an imagick.so that didn’t fail to open images or crash Apache. The trick seems to be compiling IM with –enable-embeddable.

  • PHP4 as CGI, Apache 1.3.x (”dl” is disabled in ISAPI php.)
  • wget latest ImageMagick 5 (http://www.imagemagick.com/www/download.html), unzip
  • ./configure –prefix=/home/[you] –enable-embeddable –without-perl
  • make install
  • wget latest autoconf (http://ftp.gnu.org/gnu/autoconf/)
  • ./configure –prefix=/home/[you]
  • make install
  • wget latest PECL imagick (http://pecl.php.net/package/imagick), unzip
  • phpize
  • ./configure –with-imagick=/home/[you] –prefix=/home/[you]
  • cp ./libs/imagick.so [your web root]
  • In your php, “dl([path to imagick.so]);”
  • phpinfo(), verifying presence of “imagick”, an array of supported file formats, and that phpinfo doesn’t just die at the point that the imagick info is reported.

Usage notes

  • There doesn’t seem to be any real documentation for imagick.so, just the C source, and the examples in the package (which don’t have any parameter descriptions). Nice.
  • Do not attempt to resize using the default parameters for imagick_resize in examples/resize.php. The optional geometry constraing parameter (”200+200!”) caused php.cgi to hang, taking my cpu load up to 300. Nice. I also couldn’t killall php.cgi when this happened.
  • To resize, I used: imagick_resize ($handle, [width], [height], IMAGICK_FILTER_LANCZOS, 0.75). For the final parameter: <1 => sharpen, >1 => blur.
  • To set jpeg quality: imagick_setcompressionquality($handle, [0-100])
  • I didn’t try imagick_unsharpmask, but there’s some general discussion of IM USM here: http://redskiesatnight.com/Articles/IMsharpen/