Drupal Imagemagick

A lot of Drupal sites use ImageCache and ImageAPI to automatically scale and process images for display. Most of them (the vast majority, unless I miss my guess) will be using the GD toolkit and running with mod_php embedded in Apache. This is fine in most cases, but sometimes it’s definitely the wrong thing to do; in my case, I’m processing large image files (~4M or so) and keeping my memory limit down. The easiest way to do this is to offload the processing to another process. Something like ImageMagick perhaps? With a custom action from ImageCache Actions, this is simple!

Dec 14, 2007 Currently GD2 and ImageMagick support are distributed with ImageAPI. This module is specifically for Drupal 6 and older. This module has been integrated into Drupal 7, with the exception of ImageMagick integration, which has been moved to the ImageMagick project. Differences from Drupal core's image.inc. Imagemagick with drupal 6.17. Posted by ajay1kumar1 on July 2, 2010 at 10:52am. I made a separate module for add my additional process.

A quick Google led me to an article called Create PDF thumbnails with imagecache and ImageMagick while GD is still the default toolkit which supplies the following code (simplified a little by removing the PDF-y bits):

Drupal

Alas, this code it pretty useless: because it stomps on $image->info any further actions on this $image will probably break.

Imagemagick

Thankfully, there’s an easy fix: when you update $image, make sure you update everything that needs fixing. Here’s the amended code:

ImagemagickDrupal imagemagick en

Make sure that you’ve enabled the ImageMagick toolkit, drop this code in a custom action and you’ll be on externally processing images in no time!

Php Imagemagick Sample

Drupal imagemagick site

Drupal Imagemagick Download

If ImageMagick is not installed and activated, there is only a radio button – for GD. At this point, it’s probably a good idea to Google “Drupal-ImageMagick-your hosting provider ” to see if there’s host-specific documentation for enabling Image Magick. If there is, we can proceed.