Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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

share|improve this answer
    
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. –  two7s_clash Apr 3 '11 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 Apr 5 '11 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? –  two7s_clash Apr 5 '11 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 Apr 5 '11 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. –  two7s_clash Apr 5 '11 at 19:54
add comment

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...

share|improve this answer
    
This is exactly along the lines of what I did, but a more elegant solution. This is a needed feature for Regenerate Thumbnails. +1 –  two7s_clash Nov 22 '11 at 13:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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