WordPress has a useful function for adding a new image size.
Guess what is the function name?
add_image_size function syntax in WordPress
the add_image_size function needs a name, width, height, and optional crop ability.
in_category($category, $post = null)
$name must be string, setting a unique name is required for the new image size.
$height are integers and their names represent what they do.
$crop can be true, false, or an array containing x and y position of the crop (Ex:
You can use ‘left’, ‘center’, or ‘right’ for
x position and ‘top’, ‘center’, or ‘bottom’ for
Example of adding a new image size using
add_image_size function is not challenging for a WordPress developer.
In the below example, I registered 3 different image sizes with different attributes:
//name: 500-500, with:500px, height:500px, forced crop: add_image_size("500-500", 500, 500, true); //name: custom-size, with:300px, height:200px, no crop: add_image_size("custom-size", 300, 200, false); //name: custom-cropped-size, with:150px, height:100px, crop from center: add_image_size("custom-cropped-size", 150, 100, array("center", "center"));
How to regenerate older images based on the new registered image size?
When you register a new image size, It will apply to future image uploads in the admin panel.
For regenerating image sizes for older images, you can use the Regenerate Thumbnails plugin.
I used this plugin so many times. It has an option to skip image sizes that already are available in files.