ValentinH / react-easy-crop

A React component to crop images/videos with easy interactions
https://valentinh.github.io/react-easy-crop/
MIT License
2.34k stars 167 forks source link

Safari object-fit: cover #537

Open dfrench1 opened 6 months ago

dfrench1 commented 6 months ago

Describe the bug Hi I am having a problem with object-fit and translate. When zooming and moving the image to the left or right, this causes the image to be cut off from the edge of the container. This happens when it switches between the cropped image and the cropper component. It is happening consistently on Safari browser and rarely on Chrome.

Each image has an 'Edit' button that is used to conditionally render either the Image with css translated values (when not cropping) or the Cropper component (while cropping). For ease, the sandbox is using the same image but in production it would be a variety of image width/heights

To Reproduce

  1. With Safari browser
  2. Go to https://codesandbox.io/p/sandbox/staging-voice-x3l43m?file=%2Fsrc%2FCropper.tsx%3A9%2C52
  3. Click the 'Edit' button on an image
  4. Zoom in
  5. Drag to the left or right edge
  6. Click the 'Save' button

https://github.com/ValentinH/react-easy-crop/assets/30437475/2f378fa6-c0d8-4173-8c5d-627ed1e07f4d

Expected behavior Image fits into the container after being translated to match behaviour on chrome browser

ValentinH commented 6 months ago

I'm struggling with Codesandbox on Safari so I cannot try it but adding willChange: "transform" to the image should help.

See https://codesandbox.io/p/sandbox/staging-voice-forked-h7rffm?file=%2Fsrc%2Findex.tsx%3A10%2C12

dfrench1 commented 6 months ago

thanks for the quick response, i dont have access to that sandbox

ValentinH commented 6 months ago

It should be good now 🙂

dfrench1 commented 6 months ago

great, i see you removed the cropSize prop which i hear causes more problems then solves. How would i update the aspect logic so that the crop area always fits the entire width/height of the image container?

ValentinH commented 6 months ago

You can compute it based on the width and height of the container.