让我们有一些这样的缩略图大小:
add_image_size(\'home-slide-medium\', 1000, 504, true);
add_image_size(\'home-slide-sm\', 500, 252, true);
add_image_size(\'video-poster\', 780, 512);
让我们上传一幅肖像图片,大小如下1000x3000px
如何避免创建横向缩略图(如1000x504
或500x252
) 这张肖像画?
我尝试过这样的方法,但没有成功:
add_filter( \'image_resize_dimensions\', \'custom_image_resize_dimensions\', 10, 6 );
function custom_image_resize_dimensions( $payload, $orig_w, $orig_h, $dest_w, $dest_h, $crop ){
// ie parameters: null, 1000, 3000, 1000, 500, true
// ie payload: array(0, 0, 0, 1248, 1000, 504, 1000, 504))
// if $crop is true...
if($crop ) {
// ...and if src img is portrait, skip it unless is same aspect ratio
if($dest_w > $dest_h) {
return false;
}
// else continue
else {
return $payload;
}
}
else {
return $payload;
}
}