TimOliver / TOCropViewController

A view controller for iOS that allows users to crop portions of UIImage objects
http://www.timoliver.com.au/2015/06/21/tocropviewcontroller-an-open-source-image-cropper-for-ios/
MIT License
4.73k stars 952 forks source link

How to fit a whole image inside a cropping window #357

Open georgek1991 opened 5 years ago

georgek1991 commented 5 years ago

I have an image which has height greater than its width. I want to achieve something like user can pinch zoom out to fit the whole image inside a fixed cropping window. If there is any empty space after zooming out then it should be filled with a default color like black or white. Some thing like

Screenshot 2019-05-30 at 1 38 44 PM

Can we achieve this functionality using this library?

Thanks in advance.

TimOliver commented 5 years ago

Hi @georgek1991! Sorry for the late reply.

No, it's not able to perform that sort of functionality at the moment. It's hard coded to zoom to fill the crop box, not to fit it.

It should be relatively trivial to change what the minimum zooming scale of the scroll view is to achieve this sort of effect. But that starts to bring other complexities like how do you set the background colour of the unfilled regions etc.

Would you be interested in trying to file a PR for this? If not, I might close this issue and recommend you go for your own tailored solution for what you're trying to do here.

Thanks!

CDBridger commented 4 years ago

Just commenting that I would like this functionality too. (I'm developing a react-native app with a dependency on an image picker library which uses this library for iOS).

gordonwhitehouse commented 4 years ago

+1 for this. i think you can get by with setting backdrop to black if exposing a config is too much work.

konacurrents commented 3 years ago

Tim, First I would like to say this code is some of the best designed and most flexible Ive ever seen. Thank you as it fit a need and I plugging it in very quickly. I also reuse the VC until a new image is used so I can keep cropping.

I second that I need to shrink an image to fit into one of my pre-set aspect boxes, and fill with a black background. I played around with the kTOCropViewMinimumBoxSize which lets you shrink the image, but it is resized when hitting done.

So this feature is my most important improvement request in your most excellent code. Second would be more custom aspect ratio boxes. And third would be able to retrieve the original image (as others use the VC that didn't set the image).

Thanks, scott

konacurrents commented 3 years ago

Just a followup. This is actually a trickier issue than I thought as the aspect ratio of the desired result is needed (otherwise just create a big image). Without a specified ratio, which Tim's program nicely provides, the black background and final image size are unknown. So I convert the image and then send to TOCropViewController.

If there were more customization of the aspect ratios, an appropriate image could be passed to those methods easier.

So as the user can perform much of what's needed, I don't need this feature any more. thanks, scott