admin管理员组文章数量:1204984
I have removed the default image sizes, and added my custom image sizes with this code:
// Remove default image sizes
function remove_default_image_sizes( $sizes ) {
/* Default WordPress */
unset( $sizes[ 'thumbnail' ]); // Remove Thumbnail (150 x 150 hard cropped)
unset( $sizes[ 'medium' ]); // Remove Medium resolution (300 x 300 max height 300px)
unset( $sizes[ 'medium_large' ]); // Remove Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
unset( $sizes[ 'large' ]); // Remove Large resolution (1024 x 1024 max height 1024px)
/* With WooCommerce */
unset( $sizes[ 'shop_thumbnail' ]); // Remove Shop thumbnail (180 x 180 hard cropped)
unset( $sizes[ 'shop_catalog' ]); // Remove Shop catalog (300 x 300 hard cropped)
unset( $sizes[ 'shop_single' ]); // Shop single (600 x 600 hard cropped)
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'remove_default_image_sizes' );
//
// post thumbnail sizes
add_action( 'after_setup_theme', 'vkb_setup_theme' );
function vkb_setup_theme() {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 250, 250, true );
add_image_size( 'XS', 128 );
add_image_size( 'S', 256 );
add_image_size( 'M', 512 );
add_image_size( 'XL', 1024 );
}
//
There should be XS, S, M, XL, Post_thumbnail, and the original size, that`s 6.
However when I uploaded a big image(2898 x 2346) for testing, I have 9 images, I have additional this 3 sizes: -1536x1253, -2048x1671, and one named -scaled with the size of 2560x2088.
Why do I have this additional sizes, and how can I get rid of them? Thank you.
I have removed the default image sizes, and added my custom image sizes with this code:
// Remove default image sizes
function remove_default_image_sizes( $sizes ) {
/* Default WordPress */
unset( $sizes[ 'thumbnail' ]); // Remove Thumbnail (150 x 150 hard cropped)
unset( $sizes[ 'medium' ]); // Remove Medium resolution (300 x 300 max height 300px)
unset( $sizes[ 'medium_large' ]); // Remove Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
unset( $sizes[ 'large' ]); // Remove Large resolution (1024 x 1024 max height 1024px)
/* With WooCommerce */
unset( $sizes[ 'shop_thumbnail' ]); // Remove Shop thumbnail (180 x 180 hard cropped)
unset( $sizes[ 'shop_catalog' ]); // Remove Shop catalog (300 x 300 hard cropped)
unset( $sizes[ 'shop_single' ]); // Shop single (600 x 600 hard cropped)
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'remove_default_image_sizes' );
//
// post thumbnail sizes
add_action( 'after_setup_theme', 'vkb_setup_theme' );
function vkb_setup_theme() {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 250, 250, true );
add_image_size( 'XS', 128 );
add_image_size( 'S', 256 );
add_image_size( 'M', 512 );
add_image_size( 'XL', 1024 );
}
//
There should be XS, S, M, XL, Post_thumbnail, and the original size, that`s 6.
However when I uploaded a big image(2898 x 2346) for testing, I have 9 images, I have additional this 3 sizes: -1536x1253, -2048x1671, and one named -scaled with the size of 2560x2088.
Why do I have this additional sizes, and how can I get rid of them? Thank you.
Share Improve this question edited Mar 5, 2022 at 13:18 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Mar 5, 2022 at 11:31 Botond VajnaBotond Vajna 4714 silver badges11 bronze badges1 Answer
Reset to default 0I fonud the answer here: https://gist.github.com/iftee/73cbd9f080c5c7a943cff5e806997f90?permalink_comment_id=3314876#gistcomment-3314876
I added:
unset( $sizes['1536x1536'] );
unset( $sizes['2048x2048'] );
remove_image_size( '1536x1536' );
remove_image_size( '2048x2048' );
This removes the two big image sizes, but the -scaled image size is still there
I found out this:
When a new image is uploaded, WordPress will detect if it is a “big” image by checking if its height or its width is above a big_image threshold. The default threshold value is 2560px, filterable with the new big_image_size_threshold filter. If an image height or width is above this threshold, it will be scaled down, with the threshold being used as max-height and max-width value. The scaled-down image will be used as the largest available size. In this case, the original image file is stored in the uploads directory and its name is stored in another array key in the image meta array: original_image. To be able to always get the path to an originally uploaded image a new function wp_get_original_image_path() was introduced.
source: https://make.wordpress.org/core/2019/10/09/introducing-handling-of-big-images-in-wordpress-5-3/
To remove it:
add_filter( 'big_image_size_threshold', '__return_false' );
本文标签: wordpress is generating too many Image Sizes
版权声明:本文标题:wordpress is generating too many Image Sizes 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738688636a2106970.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论