TOCropViewController icon indicating copy to clipboard operation
TOCropViewController copied to clipboard

Feature request - cropping to exact dimensions

Open sabiland opened this issue 4 years ago • 5 comments
trafficstars

It would be really cool if there was an option-logic for cropping to exact dimensions.

Anyways, great library !

sabiland avatar Mar 06 '21 08:03 sabiland

It would be really cool if there was an option-logic for cropping to exact dimensions.

Anyways, great library !

Feel free to do that yourself and make a pull request.

adincebic avatar Mar 06 '21 10:03 adincebic

Well sorry mate, besides my regular programming job I work also on my iOS app a lot, I do not have time to do it alone.

It is really a nice library, I integrated it into my app in 5 minutes :).

sabiland avatar Mar 06 '21 10:03 sabiland

Thanks for the feedback @sabiland! I'm glad you're enjoying the library.

Hmm, how exactly do you mean cropping to exact dimensions exactly? How would you see this working?

Haha, I also share the same sentiments about spending time between work and my iOS side projects. 🤣

TimOliver avatar Mar 07 '21 14:03 TimOliver

Well I was thinking just to choose exact width/height (in pixels) for cropping and then you would just move fixed rectangle around image. Though I am not sure if this feature would be helpful for most of the users.

sabiland avatar Mar 08 '21 07:03 sabiland

I needed a subset of this functionality: specifying a minimum pixel dimension. That can be obtained by configuring the TOCropViewController/TOCropView as follows:

let image: UIImage = ...
let cropController: TOCropViewController = ...
let minimumSize: CGSize = ...

cropController.aspectRatioLockEnabled = true
cropController.customAspectRatio = minimumSize
cropController.allowedAspectRatios = [
	NSNumber(value: TOCropViewControllerAspectRatioPreset.presetCustom.rawValue)
]
		
let wRatio = image.size.width / minimumSize.width
let hRatio = image.size.height / minimumSize.height

cropController.cropView.maximumZoomScale = min(wRatio, hRatio)

Though I wouldn't mind a more straightforward way of specifying that supported directly by TOCropView, that code works for me.

If you really needed an exact height and width (which I don't, so I'm not going to write the code to do it), at a glance it seems like the most straightforward way would be to add a minimumZoomScale property to the TOCropView, and connect it to the underlying scrollView in -[TOCropView layoutInitialImage] and -[TOCropView moveCroppedContentToCenterAnimated:]. Then, set both the minimum and maximum zoom scales to the same value.

jbafford avatar Apr 18 '21 01:04 jbafford