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

Resulting image from aspect ratio crop isn't actually cropped to ratio exactly #333

Open
2 tasks done
ay8s opened this issue Feb 15, 2019 · 1 comment
Open
2 tasks done

Comments

@ay8s
Copy link

ay8s commented Feb 15, 2019

  • I have read this issue template and provided all possible information.
  • I'm using CocoaPods and have run pod update before filing this issue.

Goals

Allow users to crop using aspect ratio selection.

Expected Results

Aspect ratio selection should crop to actual exact aspect ratio.

Actual Results

Selecting 4:5 ratio and cropping, the image can sometimes be 1 pixel out width or height.

Steps to Reproduce

  • Select image
  • Select 4:5
  • Crop image
  • Get width and height of generated image and check ratio.
@TimOliver TimOliver added the bug label Apr 21, 2019
@TimOliver
Copy link
Owner

Thanks for the issue @ay8s!

Hmmm, I'd definitely agree this is a bug, but I'm not sure how easy it would be to fix.

Because such large images are shrunk down to the screen, a lot of decimal point imprecision gets introduced. Whenever the desired cropping box maps to the image and there's some decimal imprecisions (eg, the X value is 4.542f), the behaviour (IIRC) is to round up to the next pixel. This might be causing your single pixel drift here.

All of the code involved with that calculation is here. https://github.com/TimOliver/TOCropViewController/blob/master/Objective-C/TOCropViewController/Views/TOCropView.m#L1062

If you want to have a look at it and see what a good way of sanity checking that it maps to the aspect ratio, that would help me a lot! :)

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

No branches or pull requests

2 participants