You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the returned crop is incorrect, and doesn't match the percentCrop.
in the crop editor area, the dashed box and the image are both correctly rendered (the dashed box is covering the entire image).
Visual Example
Expected
however, the crop inside onComplete is correctly returned when I load the same image from my computer (not the 100% cropped version that was saved to the database and retrieved later to load back).
i opened both cropped dataUrl and original file dataUrl in the browser, they look exactly the same visually.
my hack to fix this is to use the percenCrop with convertToPixelCrop inside onComplete callback.
constimage=imgRef.current;constpreviewCanvas=previewCanvasRef.current;if(!image||!previewCanvas||!completedCrop){thrownewError("Crop canvas does not exist");}// This will size relative to the uploaded image// size. If you want to size according to what they// are looking at on screen, remove scaleX + scaleYconstscaleX=image.naturalWidth/image.width;constscaleY=image.naturalHeight/image.height;constoffscreen=newOffscreenCanvas(completedCrop.width*scaleX,completedCrop.height*scaleY);constctx=offscreen.getContext("2d");if(!ctx){thrownewError("No 2d context");}ctx.drawImage(previewCanvas,0,0,previewCanvas.width,previewCanvas.height,0,0,offscreen.width,offscreen.height);// You might want { type: "image/jpeg", quality: <0 to 1> } to// reduce image sizeconstblob=awaitoffscreen.convertToBlob({type: "image/jpeg",quality: 1,});constdataURL=awaitreadFileAsDataURL(blob);
The text was updated successfully, but these errors were encountered:
Problem
pick a 430x430 image, crop with 100%, and save.
reload the image back by setting imgSrc, it triggers onComplete, returning:
the returned crop is incorrect, and doesn't match the percentCrop.
in the crop editor area, the dashed box and the image are both correctly rendered (the dashed box is covering the entire image).
Visual Example
Expected
however, the
crop
insideonComplete
is correctly returned when I load the same image from my computer (not the 100% cropped version that was saved to the database and retrieved later to load back).i opened both cropped dataUrl and original file dataUrl in the browser, they look exactly the same visually.
my hack to fix this is to use the
percenCrop
withconvertToPixelCrop
insideonComplete
callback.code for saving cropped image
The text was updated successfully, but these errors were encountered: