$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to reduce unnecessary thumbnail creation?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to reduce unnecessary thumbnail creation?

matteradmin7PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far