SVG wrong size

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
333
Posts: 3
Joined: 2013-11-10T17:07:26-07:00
Authentication code: 6789

SVG wrong size

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: SVG wrong size

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: SVG wrong size

Post 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">
snibgo's IM pages: im.snibgo.com
333
Posts: 3
Joined: 2013-11-10T17:07:26-07:00
Authentication code: 6789

Re: SVG wrong size

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: SVG wrong size

Post by snibgo »

What version of Inkscape are you running? If older than 0.48 (the current version), an upgrade may help.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: SVG wrong size

Post 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.
snibgo's IM pages: im.snibgo.com
333
Posts: 3
Joined: 2013-11-10T17:07:26-07:00
Authentication code: 6789

Re: SVG wrong size

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: SVG wrong size

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply