2

Images in WordPress posts, as I understand, are uploaded manually. They are uploaded by default to uploads folder. A client of mine reported that, in one of his site, he uploaded all the images in BMP format. Now he realized the consequences of his mistake. He wants to make them JPG now. And there are 40-60 images there.

With a photo editor I can change the images in uploads folder from BMP to JPG. But the problem is the database. I've seen that in _postmeta table images are stored with the meta_key _wp_attached_file with meta_value like 2011/01/canola2.jpg. And the same image is also in _posts table with a detailed path as guid, post_type attachment and post_mime_type image/jpeg. So may be a similar things happen to the BMP images as well.

So, along with the image file format changes in uploads folder how can I bulk edit the db to make them available only with a minor change in their format in database? Any SQL query?

Or, do I have to do the big change manually, one by one?

  • 2
    For sake of simplicity you could use a search and replace tool to change .jpg to .bmp in the DB. It takes a lot of the hassle out it. The link below is a great resource for doing search and replaces in WP databases. It even gives you a preview of what it's going to change so you can be sure your editing the right things. However, please back up your db otherwise there is no coming back from an erroneous search and replace! interconnectit.com/products/… – MichaelJames Jan 17 '14 at 21:05
  • @MichaelJames I considered that, but I found some erroneous blank replacement once in one of my database, that's why I put this in least consideration. Anyways, thanks a lot for the link and a reminder. :) – Mayeenul Islam Jan 18 '14 at 3:44
1

Assuming you add the files with the matching filenames in the appropriate wp-content/uploads/ folders you could run a few SQL queries to update the WordPress database to use the .jpg files.

Assuming your wpdb prefix is wp these queries would be:

UPDATE wp_posts SET post_mime_type = replace(post_mime_type, 'image/bmp','image/jpeg');

UPDATE wp_posts SET guid = replace(guid, '.bmp','.jpg');

UPDATE wp_postmeta SET meta_value = replace(meta_value, '.bmp','.jpg');
0

Here is a plugin that can accomplish that. https://wordpress.org/plugins/better-search-replace/

Just select wp_posts and wp_posts_meta, check the GUID box, and replace image/bmp with image/jpeg and .bmp with .jpg

I changed 5000 images in about 20 seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.