-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
Incorrect crop area output when the input is SVG #381
Comments
Indeed, something is wrong with the sizes computation. First thing I noticed is that react-easy-crop/src/Cropper.tsx Lines 245 to 246 in 4e31ef2
I guess we should use |
Cropping works with some other SVGs, for example this image https://user-images.githubusercontent.com/1442690/182855138-e84d1916-8a19-4152-89a8-4c9074f54dfd.svg Could it be that the difference is that the original svg has |
I am facing the same issue here. Is there some workaround? |
I've encountered the same issue. Only SVG's with a fixed height and width are cropped correctly. Not a perfect solution, but a workaround that worked for my use case is using the view box dimensions as a fallback values if a fixed height and width are not present. I preprocess SVG files, adding a fixed height and width, before passing to const svg = svgDoc.querySelector("svg");
if (
!svg ||
(isFixedPixelValue(svg.getAttribute("width")) &&
isFixedPixelValue(svg.getAttribute("height")))
) {
return;
}
const [, , viewBoxWidth, viewBoxHeight] =
svg.getAttribute("viewBox")?.split(/[\s,]+/) ?? [];
if (!viewBoxWidth || !viewBoxHeight) {
return;
}
svg.setAttribute("width", viewBoxWidth);
svg.setAttribute("height", viewBoxHeight);
...
function isFixedPixelValue(value: string | null) {
return value && (/^\d*\.?\d+px$/.test(value) || /^\d*\.?\d+$/.test(value));
} |
Describe the bug
When trying to crop an SVG file, the final output cropped area is wrong. So any code that relies on this output will generate wrong image output.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Crop the exact area that the user has defined using the cropper.
The text was updated successfully, but these errors were encountered: