-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
SVG Image cropped with fabric.Image.fromURL #5512
Comments
In fact, this exact cropping issue is relevant starting from 2.4.0 which introduced the breaking change. |
@RoeyMaor Thank you for the advise of downgrading to 2.3.6. I was having issues loading SVGs there were converted from .ai files. After downgrading I am no longer having issues and I can finally move on with my life! |
@RoeyMaor in your opinion which is the commit from 2.3.6 to 2.4.0 that introduced the bug? |
https://jsfiddle.net/6gbq7kfv/ with 2.3.6 behaves same to me. |
@asturur This is weird, when I use versions bigger than 2.3.6 many SVGs are messed up like this: I narrowed the possibilities for the culprit commit to one of the following: |
@RoeyMaor If you add width and height attributes to svg then there will be no cropped |
What behavior is expected without the SVG object size set? |
@0ro Your example uses 2.3.6, so it is not a counter example, Iv'e said that since 2.4.0 the bug was introduced. If adding the width and height attributes to the svg tag itself is the solution as you said, then this in itself is another bug, as the proportions for correct display should be inferred from the viewbox in case the width and the height aren't specified in the svg tag itself. Many svgs do not use these attributes |
The latest version in which the test case in issue runs correctly is 1.7.22 |
to solve this properly we need an overhauled parser. Maybe is better to invest them in a new svg parser that maints groups |
Will there be a fix for this? (or a new svg parser?? 😉 ) It works fine in Fabric 2.7.0 using Safari on the Mac, but not in Chrome (if that is important) |
Sourcefile is: https://github.com/twitter/twemoji/blob/gh-pages/svg/1f171.svg Here's what I get on Safari 12.0.1/Mac Fabric 2.7.0: Same code on Chrome 73.0.3683.75/Mac Fabric 2.7.0 Please also note, that the second layer ('B') is not showing |
svg parser is one of the funny things for me, and one of the things i would like to work on. |
Sounds familiar 😊 |
Yeah consider that parsing an svg, with all the svg capabilities is a non trivial task. The more functionalities we enable from SVG the more weird combination arrives. |
Me too! And - interestingly - the above results show fine in Safari, but wrong in Chrome; so it seems that (besides parsing svg) more things are involved |
Has there been any progress on this? Looks like its been about 8 months since this was reported and seems like a pretty major issue thats still going on |
if i remember correctly this requires a full new svg parser logic. |
Getting the same issue with version 2.4.6 when trying to load SVG using Is there any workaround? Here is the fiddle |
@satendra you can use fabric.loadsvgfromurl but that will give you a path object instead of an image. If you dont need it to be an image object, then this will at least load the full picture on canvas for you. Unfortunately all we can do right now. |
I dont know why one parser works and the other doesnt, but would it be possible to use the loadsvgfromurl to get the path object and then convert it to an image after that? Or is that basically what image.fromurl is doing already? I havent looked at the parser code myself to see |
image.fromUrl shoud draw the svg as an image, with no details loss on zoom and 0 compatibility issues. The other creates a group of objects. If you do not need to let someone else ungroup the group and manipulate every single path on the canvas, loading it as an image is a solution |
i think this has been partially fixed. |
this one? Or what do you mean? https://github.com/twitter/twemoji/blob/gh-pages/svg/1f171.svg |
yes this one is one of them. also the jester i need. |
Sorry - I was off for a couple of days... |
i think this problem has been solved in current master! |
Still having issues with version latest version 3.5.1. The SVG below renders properly on 2.3.6 which is what I've been using for quite some time. The difference between the two photos are on the right side of the image. Test SVG Logo |
Hmm interesting - this is what I did even for a simple test and still came to same conclusion:
|
the website could not include last commits |
Any news on this? Still having similar issues. |
Try version 2.3.6. I had issues as well but tried someone's recommendation above and problem got resolved. I haven't tried any newer version since then as if it ain't broke... don't fix. |
Thanks. I am using 4.3 "with gestures". I am actually using Twemojis. Adding width and height to the svg actually works. I am going to modify all Twemojis I use with a script then. |
what are twemojis? are they free to use set of emojis? |
Yes, it is a free set of emojis. Someone was mentioning it a the beginning of this thread.
|
fabricjs v5.2.1 (custom build from website for Eraser tool). Facing same issue but in Latest Safari MAC and IPhone. SVG are cropped when load from JSON. |
i went on fabricjs.com/kitchensink where there is still fabricjs 5.2.1 i loaded that svg and json saved and restored it without issue
|
I made another Image from current image then it is working now:
|
Hey folks, any updates?
|
Version
2.4.6
Test Case
https://jsfiddle.net/kbcn4mpd/
Information about environment
Tested on Chrome 71.
Steps to reproduce
See fiddle.
I try to add an image to the canvas, using
fabric.Image.fromURL()
ornew fabric.Image()
. This image is a SVG file but I don't want to be able to manipulate objects inside this SVG, I just need to manipulate this SVG as a whole image.Expected Behavior
The canvas should show the entire image (french flag).
Actual Behavior
The image appears, but is cropped: we can only see the upper left corner. I you remove the canvas'
height
attribute, then it appears correctly but then I am not able to correctly size the canvas.The text was updated successfully, but these errors were encountered: