Preserving Metadata in Images Uploaded to WordPress Sites
There has been much discussion over the years on the ControlledVocabulary.com mailing list and elsewhere about the fact that many - if not most - Web Content Management Systems (CMS) like WordPress don't preserve embedded metadata (EXIF, XMP, etc.) in thumbnails, previews and other derivative images they generate. The reasons why this happens - and the reasons for objecting to this behavior - are many and I won't go into all of them here, but there is hope.
In a nutshell, the software library many CMS's use out of the box is the popular GD - it's simple to use from PHP, and is available on almost any Apache+PHP Web host on the planet. However, GD has some real limitations and there's a better option - ImageMagick - which is also available almost everywhere. I've worked with ImageMagick for years both on the Web and off, and it's a fantastic toolkit - it does far more than GD, and generally better in every regard.
For several years now, at least, ImageMagick has preserved metadata when converting images, within the limitations of the file formats. For instance, when you hand it a large TIFF and have it scale it down and create a JPEG thumbnail, it will generally copy all the resident metadata from the TIFF to the JPEG. This is a good thing - it can be turned off, but is on by default. Sweet.
Installing ImageMagick-Engine
- Login to your WordPress site as an admin and go to your admin page, typically: http://www.yourdomain.com/wp-admin
- Click the Plugins link
- Click Add New
- In the Search Plugins box, enter "ImageMagick-Engine" and hit enter
- The first result should be the ImageMagick-Engine plugin; click Install Now and WordPress should automatically download and install it on your server.
- Activate the plugin.
- Go in to the ImageMagick-Engine plugins settings page, typically: http://www.yourdomain.com/wp-admin/options-general.php?page=imagemagick-engine
- Check "Enable enhanced image engine"
- Set Image engine to "ImageMagick Command Line"
- "ImageMagick path" should be automatically set - click the Test Path button to ensure it's available. If it isn't, try setting "Image engine" to "ImageMagick PHP Module" instead. If that doesn't work, you can't use this plugin as you don't have ImageMagick installed.
- Check the box next to every image size you want ImageMagick to process - I'd check them all if I were you.
- Hit "Save Changes" and it's all configured to process new files.
On the same page, on the far right, is a panel called "Regenerate Images". This allows you to reprocess all images previously uploaded. Simply select all the sizes you'd like to re-process and click "Regenerate". Depending on the size of your media library in WordPress, you might want to grab a beer and kick back for a bit.
Now, whenever you upload a new image to WordPress, all the various sizes of thumbnails and previews that WordPress generates will inherit all the metadata from the original.
Rock on.
Note: there are times when not preserving metadata can be a good idea, but it's better that the default is to preserve. I'll discuss this in another article in the future.