elboletaire / Watimage

:framed_picture: PHP image manipulation class
https://elboletaire.github.io/Watimage
Other
25 stars 17 forks source link

`resizemin` resize mode is not working properly in some scenarios #4

Closed albertboada closed 9 years ago

albertboada commented 9 years ago

The theory

resizemin resize mode (i.e.

$wm->resize(array(
    'type' => 'resizemin',
    'size' => array(
        'x' => $max_width,
        'y' => $max_height
));

) is intended for generating images which do not exceed the specified boundaries ($max_width and $max_height) under any circumstances, while maintaining the original aspect ratio.


The problem

This specification above is not met when following 3 conditions are given:

i.e. we want a resize which fits in portrait-shaped boundaries (e.g. $max_width = 240; $max_height = 800 )

i.e. original image is landscape (e.g. $img_width == 1200; $img_height == 900;)

i.e. original image's height is bigger than the specified boundary for height (e.g. $img_height == 900; $max_width = 800;)

Right now, the above scenario results in a generated image constrained by height, instead of by width, returning an image which does not fit in our portrait-shaped boundaries.

With the example data above, the resulting image is

final_width  = 1067
final_height = 800

, while the desired outcome is

final_width  = 240
final_height = 160

Proposal

I intend to make a pull request asap fixing this particular resize mode.