Page 1 of 1
Question about IM reading SVG Images
Posted: 2013-06-04T01:34:41-07:00
by dengshenyu
Hi folks,
I have a question about IM reading SVG Images and it really troubles me.
For the SVG image below,
Code: Select all
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" viewBox="0 0 100 100">
<defs>
<linearGradient id="grad1">
<stop offset="0%" stop-color="white"/>
<stop offset="100%" stop-color="black"/>
</linearGradient>
</defs>
<rect x="10" y="10" width="80" height="80" fill="url(#grad1)" stroke="blue"/>
</svg>
When I use "identify -verbose sample.svg", I got the result with "Geometry: 1x1+0+0". But other people get "Geometry: 100x100+0+0".
Which result is expected?
Re: Question about IM reading SVG Images
Posted: 2013-06-04T01:59:48-07:00
by GreenKoopa
100x100+0+0 seems correct to me. Have you tried changing the svg element's width, height, and viewBox attributes to different values to see what happens?
Note, I can get a different result by setting -density.
http://www.imagemagick.org/Usage/draw/#svg_settings
Code: Select all
convert -density 144 sample.svg info:
sample.svg SVG 200x200 200x200+0+0 16-bit sRGB 291B 0.031u 0:00.009
Re: Question about IM reading SVG Images
Posted: 2013-06-04T02:12:03-07:00
by dengshenyu
GreenKoopa wrote:100x100+0+0 seems correct to me. Have you tried changing the svg element's width, height, and viewBox attributes to different values to see what happens?
Note, I can get a different result by setting -density.
Code: Select all
convert -density 144 sample.svg info:
sample.svg SVG 200x200 200x200+0+0 16-bit sRGB 291B 0.031u 0:00.009
Well, I got this:
Code: Select all
$ convert -density 144 sample.svg info:
test.svg SVG 2x2 2x2+0+0 16-bit DirectClass 497b
Is the default image page not right as the SVG image use percentage in width and height?
Re: Question about IM reading SVG Images
Posted: 2013-06-04T02:26:12-07:00
by GreenKoopa
My understanding is that SVG images don't inherently have a size. So you could either try a width and height of 100px instead of 100% or
Code: Select all
convert -geometry 300x300 sample.svg out.png
Re: Question about IM reading SVG Images
Posted: 2013-06-04T02:41:14-07:00
by dengshenyu
GreenKoopa wrote:My understanding is that SVG images don't inherently have a size. So you could either try a width and height of 100px instead of 100% or
Code: Select all
convert -geometry 300x300 sample.svg out.png
If use 100px, I get this result:
Code: Select all
identify sample.svg
sample.svg SVG 100x100 100x100+0+0 16-bit DirectClass 499b
And it seems correct. But as for the percentage, why I got 1x1? When we use percentage in the svg tag, it will return a viewport with specified percentage of parent container. In this case, does it mean that the default page size is different so we get different result? Or is it a bug...
Re: Question about IM reading SVG Images
Posted: 2013-06-04T02:54:05-07:00
by GreenKoopa
Did you try -geometry to specify the "parent container" size. I believe IM determines size by using -geometry, else svg width and height if specified in pixels, else viewBox. Since your SVG file doesn't specify a size, there isn't really a correct answer. I would agree that 1x1 is an awful default. Are you using an older version of IM?