Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mikeydelamonde opened this issue Sep 3, 2014 · 1 comment

Comments

@mikeydelamonde
Copy link

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

@willherzog
Copy link

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 ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants