Let's have some thumbnail sizes like that:
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);
And let's upload a portrait image with size like 1000x3000px
How can avoid the creation of the landscape thumbnails (like 1000x504
or 500x252
) for this portrait image?
I tried something like this but it doesn't work:
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;
}
}