3

I've got several custom image sizes for my blog. One of these is setup as add_image_size( 'slide', 640, 290, true );. These are used in a header slideshow.

My problem is I've upped the dimensions of this size after many of them were originally created, and many of the attached post images are too small to be cropped to these new values (i.e. not even 640px in the first place).

So when I call up images of this size, many of them are of the old dimensions (e.g. s:5:"slide";a:4:{s:4:"file";s:52:"6a00d8341c630a53ef011570180a91970b-800wi-300x290.jpg";s:5:"width";s:3:"300";s:6:"height";s:3:"290";}. I can't use images that are this small, but no correctly sized image are overwriting these, as per above. The desired behavior is that no image would be stored for size slide instead of the old, small ones.

How can I delete these image entries in _wp_attachment_metadata? Do I do delete everything in the sizes sub-array and regenerate everything?

2 Answers 2

3

Not from personal experience (I don't use WP image management much), but I believe Regenerate Thumbnails plugin is usually recommended for rebuilding thumbnails.

5
  • Right, I use that, but if the new image size can't be generated, the old image remains instead of being deleted. I want all of those gone. Commented Apr 3, 2011 at 23:03
  • @two7s_clash: What if you would remove all resized versions of the images from the uploads directory and then run Regenerate Thumbnails again?
    – Jan Fabry
    Commented Apr 5, 2011 at 16:01
  • @Jan Fabry: I think all that would do is give me a ton of missing images. How would removing the files change anything in the database? Does the plug-in compare the database to the uploads file before in generates? Commented Apr 5, 2011 at 18:40
  • @two7s_clash: Ah, of course, you have used some of the "outdated" sized in posts before. Isn't it possible to modify Regenerate Thumbnails so it always removes the old metadata? You probably only run this plugin once, so it isn't that "dangerous" (for later updates) to modify it.
    – Jan Fabry
    Commented Apr 5, 2011 at 19:09
  • @Jane Fabry: I'm sure it is possible, but whether or not I can is another question! Thanks for the suggestion, I'll give it a whirl. Commented Apr 5, 2011 at 19:54
3

As already mentioned, Regenerate Thumbnails plugin triggers the (re)generation of image sizes which are currently defined via add_image_size() or similar.

Here is a patch to modify Regenerate Thumbnails Version 2.2.0 so it will delete any previously generated image-sizes, including older outdated sizes before creating the new sizes.

http://wordpress.org/support/topic/how-to-delete-old-thumbnail-images

Important: Note that URLs to images are hard-coded in posts and pages. Removing old thumbnails could result in broken images if they are still used somewhere on your site. You have been warned...

1
  • This is exactly along the lines of what I did, but a more elegant solution. This is a needed feature for Regenerate Thumbnails. +1 Commented Nov 22, 2011 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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