Is there a shortcut to change bulk BMP images to JPG images in a site?

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.

Read More

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?

Related posts

2 comments

  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');
    

Comments are closed.