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

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

Closed
matthewjsloane opened this issue Sep 15, 2021 · 5 comments

Comments

@matthewjsloane
Copy link

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.

@ruslanskorb
Copy link
Owner

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.

@matthewjsloane
Copy link
Author

matthewjsloane commented Sep 16, 2021

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.

@ruslanskorb
Copy link
Owner

ruslanskorb commented Sep 16, 2021

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.

@sugitatestblue
Copy link

not yet?

@sugitatestblue
Copy link

I did like this.
#242

ruslanskorb added a commit that referenced this issue May 19, 2022
…d `chooseButton` while the image is being dragged, decelerated, or zoomed.

Fixes #234, fixes #242.
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

3 participants