I want to resize images on server, I have more than 7000 images in library of my WordPress site. I want to resize all images on server itself. I know that regenerate thumbnails plugin can be used, but for that I will have to keep my browser window open all the day and it can even crash somewhere in middle that will lead me to resize all images again.

Does anyone have better idea to do this stuff? Please explain answer in brief.

2 Answers 2


Ankit you can re-size images by using this script via terminal:


ini_set('max_execution_time', 0);

require_once( './wp-admin/includes/admin.php' );


$attachments =& get_children(array(
        'post_type' => 'attachment',
        'post_mime_type' => 'image',
        'numberposts' => 50,
        'paged' => $i,
        'post_status' => null,
        'post_parent' => null
    ), ARRAY_A);

foreach ( $attachments as $attachment ) {
    $image = get_post($attachment['ID']);
    $original_size_path = get_attached_file($image->ID);

    if (false === $original_size_path || !file_exists($original_size_path)) {
        echo 'File Not Found: ';
    } else {
        $metadata = wp_generate_attachment_metadata($image->ID, $original_size_path);

        if (is_wp_error($metadata) || empty($metadata))
            echo 'Unknown failure reason: '. $original_size_path;

        wp_update_attachment_metadata($image->ID, $metadata);

echo 'Done page '. $i.' ====== ';
mail('[email protected]',('Page'.$i.'done'),('Page'.$i.'done'));
mail('youremailid+1@domain.com;','Done','Done Images Thumbnail Generation');

You just need to change the value of $i in for loop and your email address.Save this file as "something.php" and run this in your terminal via ssh. Hope this helps.


Bulk Resize Media automatically resizes huge image uploads and makes sure the maximum upload size is respected for all uploaded images. Try this plugin : Bulk Resize Media

  • Will this handle 7K images on one go ?
    – Ankit
    May 6, 2014 at 9:37
  • I have tried 3k images. it work's fine. May 6, 2014 at 9:42
  • What about your server space ? are you using shared hosting? May 6, 2014 at 9:43
  • I have dedicated hosting.
    – Ankit
    May 6, 2014 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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