imgareaselect icon indicating copy to clipboard operation
imgareaselect copied to clipboard

resizing box doesn't appear initially when height is set to height of image

Open mikeydelamonde opened this issue 10 years ago • 1 comments

Hi there,

I use this component to crop images and set the initial params to be a 1:1 square maximised in the image. e.g. if my image is 200x300 I will start with a 200x200 square. If you do this it doesn't work. If you set it to 199 px then it does. Hope you can help!

This is with the 1.0.0 rc version

mikeydelamonde avatar Sep 03 '14 16:09 mikeydelamonde

I just experienced the same issue using version 0.9.10. I believe this happens if the image is resized only via width (and, if my theory is correct, it could also happen with a maximum-width selection if the image was resized via height) because this means that the height is likely fractional (i.e. not an integer value).

I can't say I fully understand the inner workings of this plugin, but one way to solve the issue is by changing how imgWidth and imgHeight are set in the adjust() method. Change these lines:

imgWidth = $img.innerWidth(); imgHeight = $img.innerHeight();

To this:

imgWidth = Math.ceil($img.innerWidth()); imgHeight = Math.ceil($img.innerHeight());

...and you're set. The reason I used Math.ceil() instead of Math.round() is because I wanted to make sure that they always (slightly) exceed any non-rounded values in play.

@odyniec I really appreciate this plugin: it fits my use-case nicely, but better support for non-integer image dimensions might be in order ;-)

willherzog avatar Jul 13 '18 23:07 willherzog