in Web & Tech

Keep EXIF data in Drupal by using ImageMagick instead of GD

In case you’re using Drupal for some kind of photo gallery be advised that all your images’ EXIF data get removed as soon as you set maximum image dimensions for your image field (and upload images bigger than those specified dimensions).

The problem is that GD simply doesn’t support EXIF. So the solution sounds simple: Tell ImageAPI to use ImageMagick instead of GD.

To do so you first need to install the ImageMagick module and make sure your
server has ImageMagick installed.

After enabling ImageMagick module be sure to set the correct path to the convert binary. You can find it by entering whereis convert inside a terminal on your server (SSH access is required). Usually it should be something like /usr/bin/convert.

If you’re lucky that’s all you have to do. I wasn’t lucky.

In case you can’t save ImageMagick modules settings and get some error saying something about error code -1you’ll want to go ahead and apply a variation of the patch provided in this issue. In ImageMagick module remove this line if ($return_code != 0) { and replace it with if ($return_code != 0 && !($return_code == -1 && $error === '')) {

This made it possible to set the correct path to the convert binary and to change the default ImageAPI toolkit to ImageMagick. But: Now, automatic resizing to the defined maximum dimensions upon uploading stopped working completely. The message I got now went like libgomp: Thread creation failed: Resource temporarily unavailable. I checked it proc_open() was available with my PHP setup using this snippet:

if (!function_exists('proc_open')) {
    print 'proc_open is not available';

But that worked as it should.

Finally I found some TYPO3 folks having this kind of issue on servers provided by 1&1 (nope, I’m not hosting there). They suggested to force ImageMagick to use only a single thread. So I tried just putthing this command into my settings.php, et voilĂ , it works: putenv("MAGICK_THREAD_LIMIT=1");

Seems like a lot of effort for something basic like not deleting EXIF information. But better think about it before than being shocked about having lost all your images’ precious meta data.

Write a Comment