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

Need svg support #303

Closed
viperphase1 opened this issue Apr 2, 2020 · 10 comments
Closed

Need svg support #303

viperphase1 opened this issue Apr 2, 2020 · 10 comments

Comments

@viperphase1
Copy link

The cropper doesn't load svgs.

@viperphase1
Copy link
Author

Also it would be nice if there was some kind of error message when you try and load an unsupported file type.

@Mawi137
Copy link
Owner

Mawi137 commented Apr 2, 2020

If you read the readme, you'll find that there's an output that does exactly that.

The problem with an svg is that it doesn't always have a width and height. The width and height need to be set on the svg tag itself else it will not render correctly. You can try it here: https://image-cropper.stackblitz.io. I changed it so svg is allowed there.

@viperphase1
Copy link
Author

What if when someone puts in an svg without width and height information you set the size using the resizeToWidth and resizeToHeight parameters? And if resizeToWidth and resizeToHeight are not set use an arbitrary default.

@viperphase1
Copy link
Author

Or even the width of the container

@viperphase1
Copy link
Author

It's possible to edit svgs in javascript. If that's not an option I think an acceptable fallback would be to convert it to png and use the png in the cropper.

@Mawi137
Copy link
Owner

Mawi137 commented Apr 3, 2020

Using resizeToWidth is used for the resulting image, so you'll lose a lot of quality if you do that.
Converting it to a png will require a canvas to do so as well, so you'd still need the width. Unless you know another way?
I checked and having only the width in the svg tag is enough for it to render correctly in the cropper. However files are read as dataURL so I have no idea how to add the width automatically to that..

@Mawi137 Mawi137 closed this as completed Apr 12, 2020
@tuananhgk98
Copy link

@Mawi137 , i have try to upload an svg file in this domain: https://image-cropper.stackblitz.io, althought i have set the witdh and height to svg tag, so it doesn't work, plesea help me! thanks

@yinshuxun
Copy link

@Mawi137 https://image-cropper.stackblitz.io demo is not support for svg which has width attr

@jpthewes
Copy link

jpthewes commented May 18, 2021

for anyone looking into this in the future:
I could change the svg content before it came to ngx-image-cropper in the change handler for the file upload using for example the following:
https://gist.github.com/jpthewes/65c6d3da1517da7c299251bee0338608

with
<input type="file" (change)="onFileChange($event)" />

--> basically taking the height and width from the view box property as a fallback. @Mawi137 do you think something similar would be an option in the codebase itself? If so, I would make a proposal PR.

@burnacid23
Copy link

@Mawi137 try to fix the SVG for image cropper, but did not get proper solution ? Is it fixed ? if yes I dont see the code changes for SVG format, Can you suggest me the solution if fixed..

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

6 participants