How to reduce unnecessary thumbnail creation?

admin2025-06-04  2

On a site that has many different image sizes each time an image is uploaded all the different thumbnail sizes are created causing a fair bit of bloat. What would be the best way of optimising this process?

With a custom post type of ‘product’, where the different product type images have slightly different aspect orientations, should (the plugin) register all the possible image sizes? e.g.

add_image_size('small-A', 45, 67, array('center', 'center'));
add_image_size('small-B', 35, 49, array('center', 'center'));
add_image_size('small-C', 42, 65, array('center', 'center'));
add_image_size('small-D', 50, 50, array('center', 'center'));...

But assuming when the plugin creates a product A, and the front end will never use the other formats for that size; should one only register the necessary sizes for ‘A’ format before running media_handle_upload(), would that affect the front end?

Or, run remove_image_size() on all the unnecessary image sizes just before media_handle_upload()?

Or, is there a different / best-practice approach?

Obviously, impact on performance, scalability and especially impact on storage are of some concern.

Thanks in advance.

(PS. one could conceivably just generate a standard image size and place the appropriately sized image inside that with PHP, but that seems a bit like cheating and possibly creating scaling problems down the road)

On a site that has many different image sizes each time an image is uploaded all the different thumbnail sizes are created causing a fair bit of bloat. What would be the best way of optimising this process?

With a custom post type of ‘product’, where the different product type images have slightly different aspect orientations, should (the plugin) register all the possible image sizes? e.g.

add_image_size('small-A', 45, 67, array('center', 'center'));
add_image_size('small-B', 35, 49, array('center', 'center'));
add_image_size('small-C', 42, 65, array('center', 'center'));
add_image_size('small-D', 50, 50, array('center', 'center'));...

But assuming when the plugin creates a product A, and the front end will never use the other formats for that size; should one only register the necessary sizes for ‘A’ format before running media_handle_upload(), would that affect the front end?

Or, run remove_image_size() on all the unnecessary image sizes just before media_handle_upload()?

Or, is there a different / best-practice approach?

Obviously, impact on performance, scalability and especially impact on storage are of some concern.

Thanks in advance.

(PS. one could conceivably just generate a standard image size and place the appropriately sized image inside that with PHP, but that seems a bit like cheating and possibly creating scaling problems down the road)

Share Improve this question edited Jan 17, 2019 at 9:49 Andre Clements asked Jan 17, 2019 at 9:39 Andre ClementsAndre Clements 1347 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

You can use a plugin for this.

If you want to do it by writing your own code, you may use remove_image_size().

add_action('init', 'wpse325870_remove_plugin_image_sizes');
function wpse325870_remove_plugin_image_sizes() {
    remove_image_size('small-A');
}

Note that you cannot remove reserved image sizes using this function.

You don't need to remove the images if you want to increase your site speed. You can optimize and compress the images by using smush images plugin => https://wordpress/plugins/wp-smushit/

This plugin can compress and optimize all the images and increase your site speed.In this way you can also save your storage space.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748999182a315498.html

最新回复(0)