Regenerate Thumbnails

Plugin Description:

Regenerate Thumbnails allows you to regenerate all thumbnail sizes for one or more images that have been uploaded to your Media Library.

This is useful for situations such as:

  • A new thumbnail size has been added and you want past uploads to have a thumbnail in that size.
  • You’ve changed the dimensions of an existing thumbnail size, for example via Settings ? Media.
  • You’ve switched to a new WordPress theme that uses featured images of a different size.

Download:

Screenshots:

823 thoughts on “Regenerate Thumbnails

  1. God! I can’t believe this, recently i made some changes to my site and i started re-uploading pictures and swearing wordpress just yesterday for not updating the thumbs after i changed the settings. I will download this now and at least the rest of the posts will be updated more easily. You saved me tons of work! My lucky day! Thanks so much!!!

  2. Pingback: Brian.Carnell.Com » Blog Archive » WordPress Plugin to Regenerate Thumbnails

  3. Thank you for this great Plugin.
    What I am desperatly searching for is a plugin that compresses the base image as well, because some of our blog writers don’t compress their images before uploading. Maybe this could be added to?

  4. Jörn: that feature won’t be making it into this plugin as that’s not really the purpose of it (it’s just meant for thumbnails), although it wouldn’t be hard to write a plugin that compressed all images as there were uploaded.

    • Maybe I’m misunderstanding, but couldnt this be done straight in wordpress? In Settings>Media… edit the max width of the Large size (leave max height blank). Though it would be nice to know how to build max image width straight into a theme.

  5. Hey

    Great, that’s the plugin I was looking for! thanks 😉
    Tried it this morning: works nice… but the process stops systematically after approx 40 to 80 pictures 🙁 (actually, after a couple of secs: each run stops a at different picture).
    I guess a timeout might kill the stuff… culprit not identified yet (php max execution time is 30 seconds).
    Any idea?

  6. Cedric M on September 26th, 2008 at 12:31 AM wrote:

    I guess a timeout might kill the stuff… culprit not identified yet (php max execution time is 30 seconds).

    My plugin resets the max execution time (to 30 seconds) after each image to make sure it doesn’t time out.

    Try finding this in the plugin though: set_time_limit( 30 );

    And changing it to this: set_time_limit( 0 );

    See if that helps any.

    I should probably also make it skip existing thumbnails if they’re already the correct size.

  7. Nope, doesn’t change anything.

    Looks like the web server isn’t returning anything to the browser until some timeout happens, at approx 10-15 secs… (and then, it seems that the browser receives the beginning of the page in a single shot).
    I tried to add a $this->flush(); in the processing loop, no success.

    Hmm……

    Update: turning off gzip compression did solve the issue of flush() not working. Process is still stopped after ~10 secs though.

  8. Quick ‘n dirty patch to your plugin: avoids regenerating thumbnails already at the correct size.
    As my provider seems to have some watchdog to kill long running php processes, it enables me to hit the “reload” button until everything is done.

    Cheers
    Cédric

    @@ -88,6 +88,10 @@
    // Output progress so far to browser
    $this->flush();

    + // Get thumbnail max size
    + $thumbnail_size_w = intval(get_option(‘thumbnail_size_w’));
    + $thumbnail_size_h = intval(get_option(‘thumbnail_size_h’));
    +
    // Loop through each attachment
    $count = 0;
    echo ” <ol>\n”;
    @@ -100,9 +104,14 @@
    // This is a better solution than just doing set_time_limit( 0 ); in my opinion.
    set_time_limit( 30 );

    – wp_update_attachment_metadata( $attachment->ID, wp_generate_attachment_metadata( $attachment->ID, $fullsizepath ) );

    – echo ‘ <li>’ . str_replace( $uploadpath, ”, $fullsizepath ) . ” processed.</code></li>\n”;
    + $size = image_downsize( $attachment->ID, ‘thumbnail’ );
    + if (($size[1] != $thumbnail_size_w) && ($size[2] != $thumbnail_size_h) && (($size[1] + 1) != $thumbnail_size_w) && (($size[2] + 1) != $thumbnail_size_h)) {
    + wp_update_attachment_metadata( $attachment->ID, wp_generate_attachment_metadata( $attachment->ID, $fullsizepath ) );
    +
    + echo ‘ <li>’ . str_replace( $uploadpath, ”, $fullsizepath ) . ” processed.</code></li>\n”;
    + } else {
    + echo ‘ <li>’ . str_replace( $uploadpath, ”, $fullsizepath ) . ” already at the correct size.</code></li>\n”;
    + }
    $count++;
    }

  9. Great! also needed this tool.
    Thanx very much for your time and sharing your work.

    I unfortunately have a failed result. message recieved is:
    All done! Processed 0 attachments in 0.018 seconds.
    which seems a bit off since there are about 30 attachments.
    I thought it might be a hard coded path in your code, not the case.
    I am using WP 2.6.2.
    If you have any thoughts as to why this doesn’t seem to be working for me,
    I’m all ears.
    Saludos

  10. I’ve just added a new test post using the WP 2.6.2 image upload.
    And your resize plugin does work for those files.
    It doesn’t seem to be aware of images uploaded with WP > 2.5
    Which I believe was the active version when I uploaded the previous images.
    Also, my images html had been entered with modifications, I wrapped the image in a custom div if that might be a factor.

  11. My plugin only resizes actual attachments (which are stored in the database) rather than everything in the uploads folder. I believe this change was made in WordPress 2.5 (due to galleries, etc.), but I could be wrong. I’ll look into it.

  12. Yes sir, you are correct.
    WP 2.5 changed the way it relates images to posts.
    Images are related as attachments.

    A benefit is that image A can be in post L and M as attachment, which
    if you want can be clicked to view in theme/attachment.php and commented
    on independently from post L and M.

    Now to find out how to update all WP pre-2.5 posts automatically.

    Thanx again for sharing your work, and responding to my questions.

  13. Any plans to make an option where you can select the post ID for this to occur on rather than having it check all attachments? I plan on giving this a shot soon for some new photos I’ve taken. I had the medium size set up for my old camera, and well, the new one when resized to medium made the images narrower than my template. I’m assuming that if I’ve hot hard-coded to any of the medium size images, I can just delete the old ones after running the plugin, correct?

    Also another item I’m stuck on, I need a way to re-extract the exif data from images already uploaded. Do you think that would be very hard? I posted on the WP forums and got a response, but it seems over my head unfortunately.

  14. Shane on October 1st, 2008 at 7:16 AM wrote:

    Any plans to make an option where you can select the post ID for this to occur on rather than having it check all attachments?

    No, not really. This plugin is kinda in stasis for now due to a new job of sorts.

    I don’t get what you mean about the new vs. old camera though.

    As for EXIF, I take it these were uploaded pre-2.5? If so, you’d need some type of attachment importer or something. Before 2.5, the uploader was merely an uploader with a thumbnailing script. The uploads weren’t stored in the database if I remember correctly and so they weren’t tied to any posts (i.e. they were just files in a folder).

    In 2.5+, data about the images are stored in the database (EXIF, thumb size, etc. etc.). My plugin grabs all attachments outta the database and then remakes the thumbnails if the file exists in the folder. It’s not aware of any images uploaded before data about them was stored in the database.

  15. Thanks for the reply!

    What I mean about old/new camera is I set the max height and width based off of the dimensions of my old pictures, so when I used my new one, they actually make a wider shorter image, so now some of my portrait images are narrow due to hitting the maximum height that I had set up. I should have only set the width to something that pertained to my theme, and did something huge for the height.

    For my EXIF data, the images were uploaded post 2.5. My server didn’t have the exif extension installed. So now I’m stuck either reuploading the images to reextract the data, or just live w/o showing it.

    Thanks again for your reply!

  16. Shane on October 1st, 2008 at 5:00 PM wrote:

    For my EXIF data, the images were uploaded post 2.5. My server didn’t have the exif extension installed. So now I’m stuck either reuploading the images to reextract the data, or just live w/o showing it.

    Gotcha.

    It probably wouldn’t be too complex. I’d imagine it’d be similar to how this plugin works but instead of calling the thumbnailing function it’d call the EXIF function.

  17. Sweet man! I wish I had the skills to take it on. Maybe someone will try it sometime, or if you ever have any freetime and decide you’d like to make something up to do that, I’ll shoot you a contribution or donation for your time.

  18. Shane on October 2nd, 2008 at 1:51 PM wrote:

    Sweet man! I wish I had the skills to take it on. Maybe someone will try it sometime, or if you ever have any freetime and decide you’d like to make something up to do that, I’ll shoot you a contribution or donation for your time.

    I wish I did, but I’m in the process of trying to get a new job so between that and a couple existing small-time clients, I’m swamped.

  19. Pingback: 185vfx | Automatically display images in Wordpress themes

  20. Was the patch to skip correctly sized thumbs included? I’m getting some thumbs saying they’re processed, but then a fatal error of memory being exceeded. If I try to run it again it says the same thumbs have been processed, not new ones. Any ideas?

  21. kristarella on November 6th, 2008 at 6:18 AM wrote:

    Was the patch to skip correctly sized thumbs included?

    No, I’ve been busy. It currently just regenerates all images regardless.

    kristarella on November 6th, 2008 at 6:18 AM wrote:

    I’m getting some thumbs saying they’re processed, but then a fatal error of memory being exceeded.

    Sounds like you’re trying to resize an image with a very large resolution. Make sure your server has a normal sized memory limit rather than the retarded default of like 8MB (which is nothing).

    kristarella on November 6th, 2008 at 6:18 AM wrote:

    If I try to run it again it says the same thumbs have been processed, not new ones. Any ideas?

    This is normal. See the first part of this comment.

  22. Thank you a lot for the plugin.
    I have a problem with WordPress 2.7 – it shows me a message “No attachments were found. Go upload some!”

    It is strange to me.
    Anyway I found the following solution:

    instead of the line 72
    $attachments = get_children( ‘post_type=attachment&post_mime_type=image’ );
    I put
    $attachments = get_children( array( ‘post_parent’ => $post_id, ‘post_type’ => ‘attachment’, ‘orderby’ => ‘menu_order ASC, ID’, ‘order’ => ‘DESC’) );

    Now it works fine!

  23. $post_id isn’t set, so that does nothing and the order doesn’t matter either. However removing the post_mime_type may have been the real solution there. Your server may have not been marking the MIME type or something.

  24. This a fantastic plugin that exactly does what I needed! THANKS! One question: after I resized everything from 150×150 to 75×75 I noticed that all 150×150 thumbs were still in the directory of server. Would you know if there a smart and simple way to get rid of them without going through all the directories?

  25. Pingback: ?? WordPress ? Gallery ?? | Dreamcolor's Cote

  26. Same problem as Alexey above using 2.7 – his fix worked.

    Thanks for this plugin, a real time saver – it should be part of the WP core!

  27. Not even sure if you can answer Viper, but would you have any idea why all images uploaded since Jan 2008 have ‘lost’ their thumbnail info.

    I did an export from 2.7 RC1 before upgrading to 2.7, and in the process my images got all messed up. I can’t even view the images by entering in the URL to the file?

    Images w/thumbnails (all pre-2008) can be viewed?

    Tried your plugin and it claims to have processed all images, but no dice.

  28. Viper007Bond on December 16th, 2008 at 5:15 PM wrote:

    [quote comment=”226955″]I did an export from 2.7 RC1 before upgrading to 2.7, and in the process my images got all messed up. I can’t even view the images by entering in the URL to the file?

    Export? As in the XML file? That isn’t a database export, it is a content exporter. It will not save everything in your database such as settings and such.[/quote]

    Yes, the XML export. Also did a database backup, but I’ve had issues in the past rebuilding the site using just that for some reason. (database keys got screwed up)

    That last time I went through this process, I used the XML file and didn’t have any issues with the thumbnails disappearing. And like I said, all the pre-2008 stuff is in tact?

  29. Cedric M on September 28th, 2008 at 2:47 PM wrote:

    Quick ‘n dirty patch to your plugin: avoids regenerating thumbnails already at the correct size.
    As my provider seems to have some watchdog to kill long running php processes, it enables me to hit the “reload” button until everything is done.

    Cheers
    Cédric

    @@ -88,6 +88,10 @@
    // Output progress so far to browser
    $this->flush();

    +

    // Get thumbnail max size
    +

    $thumbnail_size_w = intval(get_option(‘thumbnail_size_w’));
    +

    $thumbnail_size_h = intval(get_option(‘thumbnail_size_h’));
    +
    // Loop through each attachment
    $count = 0;
    echo ” <ol>\n”;
    @@ -100,9 +104,14 @@
    // This is a better solution than just doing set_time_limit( 0 ); in my opinion.
    set_time_limit( 30 );

    wp_update_attachment_metadata( $attachment->ID, wp_generate_attachment_metadata( $attachment->ID, $fullsizepath ) );

    echo ‘

    <li>’ . str_replace( $uploadpath, ”, $fullsizepath ) . ” processed.</code></li>\n”;
    +

    $size = image_downsize( $attachment->ID, ‘thumbnail’ );
    +

    if (($size[1] != $thumbnail_size_w) && ($size[2] != $thumbnail_size_h) && (($size[1] + 1) != $thumbnail_size_w) && (($size[2] + 1) != $thumbnail_size_h)) {
    +

    wp_update_attachment_metadata( $attachment->ID, wp_generate_attachment_metadata( $attachment->ID, $fullsizepath ) );
    +
    +

    echo ‘

    <li>’ . str_replace( $uploadpath, ”, $fullsizepath ) . ” processed.</code></li>\n”;
    +

    } else {
    +

    echo ‘

    <li>’ . str_replace( $uploadpath, ”, $fullsizepath ) . ” already at the correct size.</code></li>\n”;
    +

    }
    $count++;
    }

    Please can you upload a copy of the plugin patched?! Thanks!

  30. I can’t get the patch to work either. Any chance you could update the plugin w/ the patch on this page?

    Many Thanks!

  31. Question if this will work for me: all of my thumbnail files are still in the upload directories, but my database had a minor corruption issue (postmeta table was corrupt and I restored from a backup but am missing data for past four months). Will your plugin write the thumbnail info into my database so WP will once again recognize that the thumbnails are there?

  32. having wp 2.7 i have this problem trying to “Regenerate all Thumbnails”: Fatal error: Allowed memory size of 62914560 bytes exhausted (tried to allocate 85 bytes) in xxxxxx/wp-includes/functions.php on line 2901

  33. Pingback: ????? | ?? WordPress ? Gallery ??

  34. ernesto on January 30th, 2009 at 6:36 PM wrote:

    having wp 2.7 i have this problem trying to “Regenerate all Thumbnails”: Fatal error: Allowed memory size of 62914560 bytes exhausted (tried to allocate 85 bytes) in xxxxxx/wp-includes/functions.php on line 2901

    Unrelated to WordPress version. It’s trying to resize a huge image and running out of memory to do it with. Resize the original image manually to be a bit smaller in dimensions or increase your server’s PHP memory limit.

  35. Is it possible to set thumbnail’s suffix (for example “Mini”), instead default size-base “_110x110”.
    Thanks.

  36. Hello thank you for your plug-in is really a time saving. By the way i have a problem, i have many many posts with images and the plug-in only process them partially I don’t understand way? can u help me?

    ciao leonardo

Comments are closed.