Support » Fixing WordPress » Resize all thumbnails for images already uploaded?

  • I am a bit horrified at the moment as I’ve uploaded and captioned over 700 of my 1,100 images that I’m migrating from WPG2. I didn’t realize the thumbnails we created during upload and could not be resized after the fact. It should have occurred to me but in Gallery2 you can regenerate thumbnails so I didn’t even think about it.

    What I’m looking for is a way to rerun the inline thumbnail generation on the exisitng images or if anyone knows of a plugin that will do this.

    I’ve come across a couple that are less than ideal like Resize and Save, but this only does it as you resize the image in the post. It won’t resize the thumbnails used in a gallery.

    Please, please, if anyone knows anything, I’d like to know. I invested a lot of time so that I can get proper photo/blog integration.

    Thanks in advance,


Viewing 3 replies - 1 through 3 (of 3 total)
  • run a action batch in PS or change the CSS to just show smaller/part of the larger img.

    both bad ideas. Using CSS to make images larger isn’t even an option, and using a batch script PS will do it but how will WP know the size of the new file… the filename has the dimension in the filename therefore, I assume, WP will loose the thumbnail file as it’s looking for the old filename.

    Moderator Sergey Biryukov


    WordPress Dev

    Here is the piece of code I wrote to do the trick for my thumbnails:

    function update_thumbnails() {
    	$attachments = get_children( array('post_type' => 'attachment', 'post_mime_type' => 'image') );
    	if ( !$attachments )
    	foreach ( $attachments as $id => $attachment ) {
    		$imagedata = wp_get_attachment_metadata($id);
    		$thumbnail = dirname($imagedata['file']) . '/' . $imagedata['sizes']['thumbnail']['file'];
    		if ( file_exists($thumbnail) )
    		wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $imagedata['file']));
    add_action('update_option_thumbnail_size_w', 'update_thumbnails');
    add_action('update_option_thumbnail_size_h', 'update_thumbnails');
    add_action('update_option_thumbnail_crop', 'update_thumbnails');

    It just resizes all existing thumbnails right after updating the thumbnail settings. One can put this into functions.php of a current theme or make up a plugin.

    Note that if you have a lot of files to process, the script may hit maximum execution time allowed in php.ini. I guess set_time_limit() may help in this case.

    Optimizations and other suggestions are welcome. Good luck!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Resize all thumbnails for images already uploaded?’ is closed to new replies.