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

ReactCrop__crop-mask is not updating after rotating the image. #608

Closed
rajputkamal opened this issue Nov 25, 2024 · 5 comments
Closed

ReactCrop__crop-mask is not updating after rotating the image. #608

rajputkamal opened this issue Nov 25, 2024 · 5 comments

Comments

@rajputkamal
Copy link

Hi, Please find the below screenshots FYI.

Screenshot 2024-11-25 at 2 46 54 PM Screenshot 2024-11-25 at 2 51 09 PM

In the above screenshots, after rotating the image, the crop mask is not updating in chrome and edge. In Firefox its working fine.
Can you please help on this.

@dominictobias
Copy link

dominictobias commented Nov 26, 2024

The library only works for rotating the image within the rectangle like this in the demo:

Screenshot 2024-11-26 at 12 06 28 PM

For what you're trying to achieve It would be better to rotate the image and produce a new image and load that into ReactCrop as using CSS transforms will break all the calculations in the library

E.g. user wants to rotate to the right 90 degrees -> copy image to canvas -> rotate 90deg -> render that canvas or canvas.toBlob() + URL.createObjectURL(blob) and pass url into <img />

There might be cropping libraries which allow you to rotate how you're trying out the box too I'm not sure. It is orders of magnitude more complex to implement.

@rajputkamal
Copy link
Author

My current approach.

  1. I am getting the url of the image from an external source, eg: https://some_random_image.jpg/
  2. This image url I have stored in the useState and the state I have passed to the src of image in React_crop.
  3. Now, once user clicks in rotate button, on click of rotate, I am getting rotation degree as 90, 180, 270 and 0.
  4. Once I have the rotation degree, I am passing the rotation to my image url eg: https://some_random_image.jpg/&rotation=90.
  5. Its giving me another image after rotating the image, and I am updating the state with new image url.
  6. At that time, cropper mask is not proper.

I hope my issue is clear now.
thanks!

@dominictobias
Copy link

My current approach.

  1. I am getting the url of the image from an external source, eg: https://some_random_image.jpg/
  2. This image url I have stored in the useState and the state I have passed to the src of image in React_crop.
  3. Now, once user clicks in rotate button, on click of rotate, I am getting rotation degree as 90, 180, 270 and 0.
  4. Once I have the rotation degree, I am passing the rotation to my image url eg: https://some_random_image.jpg/&rotation=90.
  5. Its giving me another image after rotating the image, and I am updating the state with new image url.
  6. At that time, cropper mask is not proper.

I hope my issue is clear now. thanks!

Ah I see that should work. Can you share the code?

In the demo if I switch between a landscape and portrait image it works, so want to understand the difference.

Screen.Recording.2024-11-27.at.4.04.37.PM.mov

@rajputkamal
Copy link
Author

can we see that during the google meet?
code is pretty big to share.

@rajputkamal
Copy link
Author

I fixed it, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants