You may need to bulk resize images because you decided to serve scaled images and speed up your site at last. Or your theme layout has been changed and you need images resized accordingly. Today we’ll discover how to resize images that are already uploaded to your WordPress site and how to resize newly uploaded images automatically on fly.
By the way, doesn’t WordPress automatically resize images?
Yes it does. Using thumbnail settings of your current theme. This is how:
Add custom image size and automatically resize images on upload
There are 4 image sizes in Twenty-seventeen WP theme by default:
To add custom image size or prevent WP from creating deafult sizes we just need to place this action in
Now when you upload any image to Media Library two default sizes ‘thumbnail’ and ‘medium’ won’t be created. Instead one additional size ‘post-preview-small’ will be added.
Also, to display or hide any image sizes on upload screen use
This is how WordPress resizes images on the fly for us.
add_image_size not working in WordPress!
There are tooons of topics out there on forums “Help! add_image_size doesn’t work! my images are not resized!”
Mind that this won’t delete or resize any already existing images, it will affect only newly uploaded images.
In order to add new sizes to images that are already uploaded to your Media Library, you need to regenerate thumbnails according to your new settings. Use this plugin, it will do everything for you in few clicks.
Resize WordPress images that are not attachments
Keep in mind that all described above will work only with WP attachments. If you need to resize images that are not uploaded through Media Library and are not WordPress attachments, you may use this advanced method of bulk resize.
In this example book covers are stored in custom fields. The max size used on site for book cover 300px *450px, so there is no point to store image large than this. We’ll resize all existing book covers to this size using GD library. This is popular PHP image processor widely supported by hosting providers out of box. Also WordPress itself has got in-built support for that through WP_Image_Editor_GD class. Great for development!
You always make backup before doing anything, right? 🙂
Wait, what if I need to resize some certain images?
Then check the result of Konstantin Kovshenin and Franz Josef Kaiser brainstorming.
Resize images before upload manually
One may notice, that the problem with auto-resizing is that it is automatic 😉 Resizing images before upload manually is the ideal approach. Detailed instructions for perfectionists are described here.