WordPress | Keep EXIF IPTC Metadata | Resized Images

Make WordPress keep IPTC EXIF metadata with resized images.

WordPress | Keep EXIF IPTC Metadata | Resized Images

This is a photographers guide on how to make WordPress keep EXIF IPTC metadata with resized images.  That’s right.  No more stripping metadata. Keep copyright, color profile, and contact information embedded in resized images.

On second thought, this guide is not just for photographers. It is for anyone who works with images containing embedded data or those who want better quality images out of WordPress’s image resizing process.

WordPress Stripping Metadata

Photographers use IPTC and EXIF metadata to embed color profile, copyright, and other information into their images. This information is stripped out when WordPress uses the GD image library to resize images. The GD library also creates poor quality files that are soft and not very sharp.

Ditch GD Image Library

The shortcomings of the GD library can be overcome by using ImageMagick to resize images.

By default, ImageMagick won’t strip your embedded data. It will keep EXIF IPTC metadata, including copyright, color profile, and contact information embedded in the resized images.  Plus, it makes your resized images look better.

Unfortunately, your server needs to have ImageMagick installed and enabled. If you are on a shared server without ImageMagick, you probably won’t be able get your hosts to install it.  You’ll have to switch to another host or another shared server that already has it installed.  I recommend US-based WestHost for reliable web hosting that is affordable.

Many people, like Eddie, will tell you that the WordPress Image API uses ImageMagick by default if it is enabled on your server. That isn’t completely true.

ImageMagick + Imagick PHP extension

Currently, WordPress will use ImageMagick as the default only if your server also has the Imagick PHP extension installed and enabled.

Basically, you should be good to go if you have ImageMagick and the Imagick PHP extension enabled on your host server.  In this case, your important metadata is safe (as of WordPress 4.5).  Those who want to retain all metadata can disable profile stripping by adding a callback function to the image_strip_meta hook that returns false.

What if your shared server has ImageMagick enabled but does not have the Imagick PHP extension?

Your host might allow you to install Imagick in your user directory and load it manually (with a custom php.ini).  This takes a bit of doing, but if they allow it, this is the only other way to get WordPress to handle everything automatically.

My preferred hosting company, WestHost, actually took the time to set everything up for me at no charge.  They installed Imagick into my directory and even supplied the custom php.ini.

ImageMagick Command-line

What about those who have ImageMagick enabled, but can’t get the Imagick PHP extension installed on the server or their user directory?

Luckily, you can use ImageMagick binary (ImageMagick command-line) instead of the Imagick PHP Module.

This news is bitter sweet because most people have no idea how to use ImageMagick command-line to generate resized images.

ImageMagick Engine Plugin for WordPress

Imagemagick Engine keeps EXIF IPTC metadata with resized images

Imagemagick Engine banner depicting a resized image with embedded data retained.

ImageMagick Engine is a plugin for WordPress that enables the ImageMagick command-line to generate resized images.

ImageMagick Engine is sorta maintained (sparingly) and can go years without updates. Thankfully, it still works on WordPress 4.9.8.

WordPress members occasionally provide update modifications (hacks) in the support section.

The hacks might not be necessary if you are only using the plugin for the command-line feature.  Either way, I recommend you apply the mods anyway.  I did and everything works great.

Make these modifications immediately after you install and activate the plugin:

  1. From the WordPress Dashboard, Go to Plugins > Editor
    1. plugin-editor
  2. Select ImageMagick Engine from the Select plugin to edit drop box.
  3. Click the Select button.
  4. Under Plugin Files click imagemagick-engine.php (it will probably already be selected).
    1. edit-plugin-screen-imagemagick-engine
  5. Make the following updates (use your browser Find Feature to make searching for the lines easier, etc..):

Source. Replace this line:

if (!gd_edit_image_support($post->post_mime_type))

With this line:

if (!wp_image_editor_supports(array('mime_type' => $post->post_mime_type)))

Source. Replace this line:

Note: Version 1.5.4 added several lines of code. It also deleted the line I am asking you to replace. You might skip this hack and come back to it if you encounter issues with transparency/alpha or PNGs. 

Me, I added the hack in the space where the old line use to be under the “// Resize file using PHP Imagick class” section. It is placed above the “if ( $resize_mode == ‘size’ )
$im->stripImage();” part.

One day i’ll test it but for now this note remains.

if ( method_exists( $im, 'setImageOpacity' ) )
 $im->setImageOpacity( 1.0 );

With this line:

if ( method_exists( $im, 'evaluateImage' ) )
 $im->setImageOpacity( 1.0 );
 $im->evaluateImage(Imagick::EVALUATE_MULTIPLY, 1.0, Imagick::CHANNEL_ALPHA);

Source. Replace this line:

$script_pages = array( $ime_page, 'media.php', 'media-new.php', 'media-upload.php', 'media-upload-popup', 'post.php'); 

With this line:

$script_pages = array( $ime_page, 'media.php', 'media-new.php', 'media-upload.php', 'media-upload-popup', 'post.php', 'upload.php');

Source. Note: read the source. Add this line:

, 'medium_large' => __('Medium Large', 'imagemagick-engine')

Below this line (around line number 140):

, 'medium' => __('Medium', 'imagemagick-engine')
  1. Click Update File button.

Note: you might have to redo the above hacks if you deactivate the plugin and then later activate it again. It is worth checking.

Also, please check the source links provided to get a better idea of what you are doing and for additional tips.

How to Use the ImageMagick Engine

Now you are ready to begin. In your WordPress admin, go to the Settings menu and click ImageMagick Engine.

setting-imagemagick-engine

Configure the plug-in.

  1. Tick the check box labeled Enable enhanced image engine.
  2. Image engine: Choose either Imagick PHP Module or ImageMagick command-line. Use whichever option gives you the green check mark at step 3.  You’ll use ImageMagick command-line if you’re one of the unlucky ones who doesn’t have the Imagick PHP extension. Otherwise, you might not need this plugin (unless you like some of the features it offers ;-).
  3. ImageMagick Path, in my case I used /usr/bin
  4. ImageMagick quality: You can only use 70 and above.  If your not careful, some resized images might turn out larger in size (KB) than the original.  This forum touches on the idea: http://www.imagemagick.org/discourse-server/viewtopic.php?t=22696I tested different quality settings for the plugin with my typical JPEG (created with 65 quality and 75 resolution).  I liked the 85 quality setting.  But there isn’t a one size fits all with the settings. Everyone has different resize outputs and quality inputs. So, run some test before regenerating your whole library.
  5. Optimize for: The list showed all image sizes that my theme has set in its functions.php. I choose the Quality radial for all of them.
  6. Click Save Changes button

Keep EXIF IPTC Metadata

Regenerate old images.

The plugin has a panel to the right that gives you the option to regenerate all images on your site with the ImageMagick Engine. The panel listed all image sizes that my theme has set in its functions.php.

This is a great but wonky feature. It takes the original images and makes new resized images to replace the old ones that were generated with the GD library.

I do not recommend trying to resize all of them at once. Depending on the amount and size of images, the process will tax your servers’ resource limits. The result is a stall or hang and that is what happened to me (I am on a shared server).

A safer way is to tick only one check box, then click the regenerate button. Repeat with a different checkbox ticked until you run through all of them, etc…. This method can still be wonky at times.

regenerate images to keep EXIF IPTC Metadata

Regenerate to keep EXIF IPTC Metadata in WordPress resized images.

The ultra safe way is to go through your important posts or pages individually one by one.

  1. Inside a post or page click on the Add Media
  2. In Media Library, choose “Uploaded to this post” from the drop box.
  3. Only images in the post should be visible.
  4. Select an image and then click the Resize using ImageMagick button on the right.
  5. Repeat for each image.

Note: Visit this support thread for some other insights.

Conclusion

I hope this guide was informative and useful.  Leave a comment if you have any questions, additional information or if you just want to say hi.

WordPress | Keep EXIF IPTC Metadata | Resized Images

Share the post by clicking one of the share buttons.

2 thoughts on “WordPress | Keep EXIF IPTC Metadata | Resized Images

  1. Anyone know the ImageMagick path for fasthosts hosting?

    I have tried

    /usr/bin

    and many variants

    but no luck

Leave a Reply

Your email address will not be published. Required fields are marked *