sekoyo / react-image-crop

A responsive image cropping tool for React
ISC License
3.89k stars 344 forks source link

when load a cropped image, there is a strange crop range projection on the image #603

Open LuckyLuo opened 2 months ago

LuckyLuo commented 2 months ago

react-image-crop package version: "^11.0.6"

We use canvas to draw an image and feed it into ReactCrop, and with initial percent crop data from last saved crop.

<ReactCrop
            minWidth={5}
            minHeight={5}
            crop={percentCrop}
            onChange={(_, _percentCrop) => {
              setPercentCrop(_percentCrop);
            }}
            keepSelection
          >
            <canvas ref={previewCanvasRef} aria-label="transform preview" className={classes.imageCanvas} />
</ReactCrop>

Issue:
There is a strange crop range projection on the image. See the picture below:

image

When start to drag the crop selection, then that strange crop range projection is gone. See the picture below:

image

But after the cropping, when you re-open the image with cropped data again, the strange crop range projection shows up again. Can you please help me to identify how to get rid of this strange crop range projection? Is it a style issue somewhere when displaying the canvas-drawn image inside ReactCrop? Thanks

LuckyLuo commented 2 months ago

Found a workaround here: https://github.com/sekoyo/react-image-crop/issues/579#issuecomment-2329566161

Remove default crop value const [crop, setCrop] = useState(); Instead, do it on imageLoad with setCrop({ ... })