ruslanskorb/RSKImageCropper

Prevent user from cropping a photo with edges outside of the image boundary

matthewjsloane opened this issue ยท 5 comments

Hi all, I noticed that if you use the image cropping tool and have one or more edges that extend past the image boundary, it is possible for the cropped image that is returned to be non-square (unequal width and height). I am using the circular image mask.

In the Contacts app, it prevents you from pressing the submit button while your cropping mask extends past the image boundary.

In my own app, I plan to work around this by preventing submission while the cropped image is not square, or resizing/recentering the image based on the smaller width/height if the sides are unequal.

I was wondering if there were any plans to do any of the following:

  1. Prevent the user from submitting a cropped image while the mask extends past the image boundaries
  2. Prevent the cropped image mask from going outside of the image boundaries
  3. Exposing a delegate method on the picker controller that signals whether the mask is outside the image boundaries or whether the user is currently dragging/interacting with the image mask.

Thanks in advance for your help, and if this functionality already exists and I'm just missing something, please let me know.

Hi @matthewjsloane,

Thank you for the question!

You probably need the avoidEmptySpaceAroundImage property of RSKImageCropViewController. It determines whether the image will always fill the mask space. Default value is NO.

Hi thanks for the quick response. I noticed that property but it seems like it only prevents the mask from exceeding the image boundary after the user stops dragging the mask. If the user taps the submit button while the mask is still being dragged, it's possible for there to be empty space still as far as I can tell -- let me know if that's not the case.

If I understood you correctly, you are looking for a way to configure the bounces and bouncesZoom properties of RSKImageScrollView. By setting them to NO, it is possible to achieve the effect you want.

At the moment RSKImageCropper has no such functionality. But it is possible to add new properties bounces andbouncesZoom to RSKImageCropViewController, similar to the properties alwaysBounceHorizontal and alwaysBounceVertical.

viewController.avoidEmptySpaceAroundImage = YES;
viewController.bounces = NO;
viewController.bouncesZoom = NO;

If you get the chance to do this and open the PR, I'll be happy to add these changes to RSKImageCropper.

not yet?

I did like this.
#242