TOCropViewController icon indicating copy to clipboard operation
TOCropViewController copied to clipboard

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

Open ay8s opened this issue 6 years ago • 1 comments
trafficstars

  • [x] I have read this issue template and provided all possible information.
  • [x] 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.

ay8s avatar Feb 15 '19 01:02 ay8s

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! :)

TimOliver avatar Apr 21 '19 10:04 TimOliver