AFAIK,Wordpress 仅在所需图像尺寸较小时(而不是在目标尺寸相同时)才生成缩略图(例如,“大”)。
我用
add_image_size( 'referenzen-big', 627, 490, true );
因此,如果我的客户上传一个 627x490px 的文件,将使用原始图像。
但这并不是我们所希望的,因为这种习惯是出于善意,会以正确的大小上传图像,并且还可以进行最高的 .jpg 压缩。在这种情况下,这导致图像大约为 300kB。
一种实用但技术上并非完美无缺的方法是要求他上传 628x490 的图像,因此宽度增加 1px,从而强制重新缩放。这样的建议将不被接受:-)
到目前为止,我已经调查了负责图像创建的钩子(Hook),并跟踪了负责的函数;这是我找到的最后一个钩子(Hook):
image_make_intermediate_size()
这是负责实际调整大小的函数:
image_resize_dimensions() .
甚至有一句台词:
// if the resulting image would be the same size or larger we don't want to resize it
if ( $new_w >= $orig_w && $new_h >= $orig_h )
return false;
那么如何启用此“强制调整大小”功能?
最佳答案
这是您正在寻找的解决方案,将放在您的 functions.php 文件中:
function thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ){
if ( !$crop ) return null; // let the wordpress default function handle this
$aspect_ratio = $orig_w / $orig_h;
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = round($new_w / $size_ratio);
$crop_h = round($new_h / $size_ratio);
$s_x = floor( ($orig_w - $crop_w) / 2 );
$s_y = floor( ($orig_h - $crop_h) / 2 );
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
add_filter( 'image_resize_dimensions', 'thumbnail_upscale', 10, 6 );
可以在这里找到:
https://wordpress.stackexchange.com/questions/50649/how-to-scale-up-featured-post-thumbnail
它将放大图像并为所有图像尺寸生成缩略图。唯一的失败,可能不是失败,是无论你会为所有上传的图像的每个图像大小获得一个单独的文件......即使它是一个小图标或其他东西。希望这可以帮助。
关于image - 强制 Wordpress 创建与上传图片大小相同的缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13460188/