I’ve an image-oriented project. Images comes in different dimention and orientation. Based on following rules i’m generating smaller images:

add_image_size('big_xxl', 4500, 9999); // 4500 x flex_height
add_image_size('big_xl', 3300, 9999);  // 3300 x flex_height
add_image_size('big', 2100, 9999);     // 2100 x flex_height
add_image_size('medium', 1250, 9999);  // 1250 x flex_height

Considering that add_image_size( string $name, int $width, int $height, bool|array $crop = false ) I need to find a way to generate images with FLEXIBLE_width but FIXED_height, for same image key (string $name).

Explanation:

Current code supports only landscape-images. I need to achieve portrait images, that based on FIXED_height value.

I see an approach to declare second set of image sizes for portrait images (big_xxl_portrait, big_xl_portrait and so on, where int $width will be '9999') ,and define what to display on front-end based on the if($image_is_portrait){...}else{...} logic.

Asking if it’s possible to generate image of the same string $name, wich size will depends on original picture orientation, since having unesessary copies of those images will dramaticaly increase server costs (doulbe storage value reuired) and it’ll be a file-mess in total.

Update:
Editing question in order to bump-up an issue-tread

1 Answer
1

What you’re asking for is functionally equivalent to scaling images to fit within a bounding square of each size, so could be achieved with this:

add_image_size('big_xxl', 4500, 4500);
add_image_size('big_xl', 3300, 3300);
add_image_size('big', 2100, 2100);
add_image_size('medium', 1250, 1250);

Consider a landscape image that is 5000×500. These rules will generate images scaled to 4500, 3300, 2100 and 1250 wide.

For a portrait image of 500×5000, these rules will generate images scaled to 4500, 3300, 2100 and 1250 high.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *