Question about IM reading SVG Images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dengshenyu
Posts: 6
Joined: 2013-06-02T03:56:44-07:00
Authentication code: 6789

Question about IM reading SVG Images

Post 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?
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Question about IM reading SVG Images

Post 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
dengshenyu
Posts: 6
Joined: 2013-06-02T03:56:44-07:00
Authentication code: 6789

Re: Question about IM reading SVG Images

Post 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?
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Question about IM reading SVG Images

Post 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
dengshenyu
Posts: 6
Joined: 2013-06-02T03:56:44-07:00
Authentication code: 6789

Re: Question about IM reading SVG Images

Post 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...
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Question about IM reading SVG Images

Post 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?
Post Reply