Replace stripped-away metadata on your WordPress server with this quick workaround
If your WordPress hosting provider makes ImageMagick available for your site, that’s good news. It’s good news for metadata. It’s good news for image optimization. It’s just a great day all around.
But what if you’re stuck with GD? Is there a way to fix the metadata damage that library inflicts? Yes. Probably. Maybe. I have a workaround for you. It works for most sites, depending on what sort of access your hosting provider grants.
You’ll need FTP access
If you have FTP access to your site, this will work. Most hosts that I’m familiar with do provide FTP access for self-hosted sites. But your luck may vary. (And since you’re probably reading this because your provider already doesn’t provide ImageMagick, you might want to hold off on buying that lottery ticket.) WordPress.com, by the way, does not support FTP access for its users.
Your hosting provider may have given your FTP credentials when you first opened your account. Or, your FTP details may be somewhere on your account’s homepage. Or, maybe there are instructions in the support documentation. Or, you might have to use your account’s control panel to enable an FTP account. Or, quite likely, you’re already well familiar with all that and you’re just waiting for me to get on with this.
If you’re not familiar with using FTP, there are lots of How-Tos on the web. Just Google “FTP and WordPress”.
Step by step
What we’re going to do here is FTP to our WordPress server, grab the image files that have been stripped of their metadata, paste the metadata back on and put the files back where we found them.
Fire up your FTP client. If you need an FTP client, Filezilla is a good one. I use it. And it’s free. But they all work, FTP isn’t brain surgery.
- Connect to your WordPress server. Now, your FTP root may be the your home directory, or it may be the web root for your site, or it may be any arbitrary directory that some admin (or you) thought would be good. We’ll assume that it’s your home directory. If it’s your web root, no worries. You’ll just start a click or so closer to your destination.
- From your FTP root, navigate to your web root. It will be called something like “public_html”, or “htdocs” or the like. Inside it, you’ll see a bunch of WordPress files and directories, “wp-this or that”.
- Find “wp-content” and open it.
- Now find “uploads” and open it.
- Uploads will (usually) contain subdirectories for each year and then, inside, each month. Navigate into the correct month’s subdirectory.
(You can make a shortcut in your FTP client to save drilling through so many directories.)
Once we have safely arrived in the correct directory, we’ll be looking at our media files. Each image will appear along with several resized copies. (Four, by default)
These resized versions of the image are served to visitors responsively, according to the size of the visitor’s viewport. The original, or full-sized, image is exactly the file that you uploaded to your Media Library. It will have its metadata just as it did when it was on your desktop. The smaller ones, which have dimensions appended to their filenames, were created by your imaging library. If that’s GD and not ImageMagick, these files will stripped of all metadata. We’ll fix that.
- Download one or more complete sets of pictures, including the full-sized one(s).
(Don’t worry about interrupting visitors’ access to the images. You’re copying them. The files will be available on your site while you work on them. There will only be a period of a second or so, when we put the files back, when each file wouldn’t be available.)
On your computer, paste back your metadata
- Now, you should have the images on your local computer, in whatever folder you chose in your FTP client.
- Open that folder (I just use the desktop) in a suitable metadata-editing tool. Photo Mechanic or XnView are good choices. I’m going to use Photo Mechanic.
If you look at your files’ metadata (“I”, or the tooltip in Photo Mechanic), you’ll see that the full-size one has all its metadata in place. The others are stripped clean. We’re going to simply copy the metadata from the full-size image and paste it on the other files.
- In Photo Mechanic, the easiest way to is to take an IPTC snapshot of the big image and paste it on the smaller ones. It takes less time than reading this paragraph. See this post for detailed instructions on Photo Mechanic’s various metadata tools.
In XnView, the process is a little different. You’ll open the IPTC panel for the big image, save its metadata to a reusable template, and apply that to the other files. See my post on moving templates between programs for a fuller explanation.
- Repeat the process for each set of images you downloaded.
Upload the images again
- Now, upload the resized versions of the images right back to where you found them. There’s no need to upload the full-size ones. We didn’t do anything to them. We only copied their metadata. Uploading them would just be a waste of bandwidth.
- During your upload, you’ll need to tell your FTP client to overwrite the files on your server with your new, fixed, files. FileZilla has a handy radio button that lets you overwrite all files in your current upload queue. In other FTP clients, You may have to click once per file.
Your repaired images will be exact replacements for the files you downloaded, except for being a few kilobytes bigger and having working metadata.
Test to see that it worked
Now you’ll probably want to go to your website and right-click and download one of your pictures to assure yourself that your work-around-ing did indeed, work. You won’t need to do this next time.
If you put fifty photos on your website whenever you post, fixing your metadata like this could be a fair amount of work. If you’re like me and it’s a half-dozen or so pictures at a time, we’re only looking at a minute or two. It’s just a matter of making it a habit. (Full disclosure: The server on which you’re reading this is ImageMagick-challenged. I haven’t fixed the photos in last week’s post. I’ll take care of them when I post this.)
There you have it. Hopefully, this technique will tide you over until you can get that ImageMagick situation in order. And yes, the technique can be used for other stuff, like running ImageOptim (in lossless mode, please) on your resized files while you have them in front of you. Just be sure not to change the images’ dimensions.
Stay tuned. In future posts, I’ll look at optimizing images for WordPress in a metadata-safe manner, and I’ll do How-Tos for that task in our supported range of software. And, oh yeah, I owe you a metadata How-To for XnView. Dive into the comments and…comment.