WordPress.org

Ready to get started?Download WordPress

Forums

Resize all thumbnails for images already uploaded? (4 posts)

  1. skaufmann
    Member
    Posted 5 years ago #

    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,

    Scott
    http://www.karieandscott.com

  2. noname1
    Member
    Posted 5 years ago #

    run a action batch in PS or change the CSS to just show smaller/part of the larger img.

  3. skaufmann
    Member
    Posted 5 years ago #

    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.

  4. Sergey Biryukov
    WordPress Dev
    Posted 5 years ago #

    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 )
    		return;
    
    	foreach ( $attachments as $id => $attachment ) {
    		$imagedata = wp_get_attachment_metadata($id);
    		$thumbnail = dirname($imagedata['file']) . '/' . $imagedata['sizes']['thumbnail']['file'];
    
    		if ( file_exists($thumbnail) )
    			@unlink($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!

Topic Closed

This topic has been closed to new replies.

About this Topic