Page 1 of 1

SVG wrong size

Posted: 2013-11-10T17:20:05-07:00
by 333
ImageMagic is reading SVGs as 25% larger than they are.

Code: Select all

$ cat test.svg
<svg width="100" height="100">
<rect width="100%" height="100%" fill="white"></rect>
<text x="20" y="20">Text</text>
</svg>

$ identify test.svg 
test.svg SVG 125x125 125x125+0+0 16-bit sRGB 124B 0.010u 0:00.030
I'm using ImageMagick 6.8.7.5-1 on Arch Linux.

Re: SVG wrong size

Posted: 2013-11-10T18:59:05-07:00
by fmw42
I am on IM 6.8.7.5 Q16 Mac OSX and I get

identify tmp.svg
tmp.svg SVG 100x100 100x100+0+0 16-bit sRGB 123B 0.000u 0:00.009

Re: SVG wrong size

Posted: 2013-11-10T20:05:00-07:00
by snibgo
I get 100x100 pixels on v6.8.7-0 Windows 7.

What text output do you get from:

Code: Select all

convert -verbose test.svg r.png
You haven't specified the units of width and height. You may find that specifying pixels ("px") makes a difference, eg change the SVG to:

Code: Select all

<svg width="100px" height="100px">

Re: SVG wrong size

Posted: 2013-11-11T03:03:20-07:00
by 333
I get the same result after specifying px.

Code: Select all

$ convert -verbose test.svg r.png
"inkscape" "test.svg" --export-png="/tmp/magick-6362JTDgGLI4XVXO" --export-dpi="90,90" --export-background="rgb(100%,100%,100%)" --export-background-opacity="1" > "/tmp/magick-63624Cl3pD2T1YK6" 2>&1
test.svg SVG 125x125 125x125+0+0 16-bit sRGB 128B 0.050u 0:00.269
test.svg=>r.png SVG 125x125 125x125+0+0 8-bit sRGB 136c 959B 0.020u 0:00.020

$ identify r.png 
r.png PNG 125x125 125x125+0+0 8-bit sRGB 136c 959B 0.000u 0:00.000
rsvg-convert uses the correct sizes

Code: Select all

$ rsvg-convert -f png test.svg -o test.png
$ identify test.png
test.png PNG 100x100 100x100+0+0 8-bit sRGB 772B 0.000u 0:00.029
more version numbers:

Code: Select all

perl 5.18.1-1
libltdl 2.4.2-12
lcms2 2.5-2
libxt 1.1.4-1
fontconfig 2.11.0-1
libxext 1.3.2-1
liblqr 0.4.2-1
libcl 1.1-3
librsvg 1:2.40.0-1

Re: SVG wrong size

Posted: 2013-11-11T06:30:52-07:00
by snibgo
What version of Inkscape are you running? If older than 0.48 (the current version), an upgrade may help.

Re: SVG wrong size

Posted: 2013-11-11T07:01:57-07:00
by snibgo
If you can't upgrade Inkscape, a workaround may be to use density:

Code: Select all

convert -verbose -density 72 test.svg r.png
However, this is a kludge (a bug to workaround a bug). "-density 72" is usually wrong.

Re: SVG wrong size

Posted: 2013-11-11T18:20:07-07:00
by 333
I didn't have Inkscape installed; my package manager doesn't list it as a dependency.
With Inkscape installed the sizes are correct. The density option also works, without Inkscape.
Is Inkscape required to work with SVGs, I would assume it to just fail without it if that were the case. I may ask the package maintainer to add it as an optional dependency.

Re: SVG wrong size

Posted: 2013-11-11T19:05:42-07:00
by snibgo
From your "convert -verbose" I thought convert was calling Inkscape. No, Inkscape isn't required for SVG. If it isn't installed convert will use internal libraries. Maybe after trying and failing to call Inkscape, with the corret 90 dpi, it then used the same dpi internally, though that should be 72, I think. A developer would need to experiment and comment.

There may be something peculiar in your installation so convert thinks Inkscape is available when it really isn't.

Inkscape is needed for some of the more complex SVG features. I don't know exactly what. I always use it with Inkscape, though it is probably faster not to.