I'm currently working on a gallery plugin similar to the one found on Posterous. I'm needing all images in the gallery in a very small thumbnail-size. Probably only 50px wide.

What's the best practice to implement the image resizing?

1.) Adding the Image size via add_image_size()?
This method has the obvious disadvantage, that all previously uploaded images aren't resized and cannot display properly.

2.) Using timthumb.php or other scripts to resize the thumbnails on the fly?

1 Answer 1


Its best practice to always use internal WordPress API functions that already exist in place of external scripts.

You would need to regenerate the thumbnails yourself, which is not overly difficult, if for instance you give yourself a head start and study the source code of existing and similar solutions;

  1. Regenerate Thumbnails Plugin
  2. Simple Image Sizes

...which are two plugins designed to do just the very thing.

Also the following is an extract from this answer on the same subject which may also in turn be taken as sample from the Regenerate Thumbnail plugin as an example or be based upon it for example sake. Either way the same suggestion applies "see how others are doing it"...

function regenerateThumbnails() {

    $images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%'" );

    foreach ( $images as $image ) {
        $id = $image->ID;
        $fullsizepath = get_attached_file( $id );

        if ( false === $fullsizepath || !file_exists($fullsizepath) )

        if ( wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $fullsizepath ) ) )
            return true;
            return false;

Sorich87 said...

Note: This function is not very scalable. It will loop through all the images and regenerate thumbnails one by one, which may consume a large amount of memory. So, you may want to enhance it.

...and I agree, but at least it plants the seed. Refer to the attachments section of the Function Reference in the Codex for a list of common image related functions, in particular (but not limited too),

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.