How to regenerate WordPress thumbnails via Bash?

Our website has a lot of images (around 30.000). I’m looking for a way to regenerate all thumbnails, as our website’s layout has changed. Using a plugin is not reliable as it requires a browser.

So, is there any way to regenerate all thumbnails via BASH?

Read More

NOTE: the images should have the following sizes: 630×290 and 960×495. Images should be center-cropped.

Related posts

Leave a Reply

2 comments

  1. You could use imagemagick’s convert.

    http://www.imagemagick.org/Usage/resize/#resize

    As example use of it in a bash script is this:

    while IFS= read -r FILE; do
        echo convert "$FILE" -resize "630x290" "${FILE%.???}.630x290.jpg"
        echo convert "$FILE" -resize "960x495" "${FILE%.???}.960x495.jpg"
    done < <(find -type f -iname '*.jpg')
    

    Remove echo when you think it’s the right command already.

  2. i don’t know about BASH,
    but you can regenerate your post thumbnails without any plugin, just put the below code in your theme functions.php

    add_action('image_save_pre', 'add_image_options');
    function add_image_options($data){
        global $_wp_additional_image_sizes;
        foreach($_wp_additional_image_sizes as $size => $properties){
            update_option($size."_size_w", $properties['width']);
            update_option($size."_size_h", $properties['height']);
            update_option($size."_crop", $properties['crop']);
        }
        return $data;
    }