Conversion of SVG to other formats does not correctly work

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
alex.schneider
Posts: 3
Joined: 2016-06-03T04:36:05-07:00
Authentication code: 1151

Conversion of SVG to other formats does not correctly work

Post by alex.schneider »

Conversion of SVG images to other formats does not always correctly work.

My ImageMagick Version is:

Code: Select all

$ convert -version

Code: Select all

Version: ImageMagick 7.0.8-8 Q16 x86_64 2018-07-26 https://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: https://www.imagemagick.org/script/license.php
Features: 
Delegates (built-in): freetype jng jpeg lcms png webp xml
The commands I've tried are very simple:

Code: Select all

convert test.svg convert.png
and

Code: Select all

magick test.svg magick.png
test.svg:
https://drive.google.com/file/d/1j5jdjF ... sp=sharing

convert.png
https://drive.google.com/file/d/1jLZaLW ... sp=sharing

magick.png
https://drive.google.com/file/d/1xnlw5q ... sp=sharing
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Conversion of SVG to other formats does not correctly work

Post by snibgo »

It seems to work fine with IM v7.0.7-28 and Inkscape 0.91.

I guess you don't use Inkscape as the delegate. I suggest you install it.
snibgo's IM pages: im.snibgo.com
canavan
Posts: 23
Joined: 2013-02-18T10:12:03-07:00
Authentication code: 6789

Re: Conversion of SVG to other formats does not correctly work

Post by canavan »

We're indeed using the "builtin" SVG coder, and not rsvg or Inkscape, since those have way too many dependencies for our taste.

Actually the Image as rendered by ImageMagick 7.0.8 is a marked improvement over 7.0.7, in that the `<use transform=` statements have an effect at all, it's just that the coordinates are not correctly computed, they seem to be off by 45°. Previously, there was only a single black drop and one crown.
canavan
Posts: 23
Joined: 2013-02-18T10:12:03-07:00
Authentication code: 6789

Re: Conversion of SVG to other formats does not correctly work

Post by canavan »

The cause here is apparently that the builtin svg renderer assumes that x==y if y is not specified in e.g.

Code: Select all

transform="translate(-168)".
If I expand that to

Code: Select all

transform="translate(-168, 0)"
the image looks perfectly fine.

According to https://developer.mozilla.org/en-US/doc ... /transform

The translate(<x> [<y>]) transform function specifies a translation by x and y. If y is not provided, it is assumed to be zero.

Proposed Patch:

Code: Select all

diff --git a/coders/svg.c b/coders/svg.c
index 4505bb483..5d5f3452f 100644
--- a/coders/svg.c
+++ b/coders/svg.c
@@ -2222,7 +2222,7 @@ static void SVGStartElement(void *context,const xmlChar *name,
                               (*p == ','))
                             break;
                         affine.tx=GetUserSpaceCoordinateValue(svg_info,1,value);
-                        affine.ty=affine.tx;
+                        affine.ty=0;
                         if (*p != '\0')
                           affine.ty=GetUserSpaceCoordinateValue(svg_info,-1,
                             p+1);
The same change may be necessary in line 1835 of coders/svg.c
Last edited by canavan on 2018-07-27T09:52:03-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Conversion of SVG to other formats does not correctly work

Post by snibgo »

Many thanks for your diagnosis. I hope a developer will apply your patch(es).
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Conversion of SVG to other formats does not correctly work

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
canavan
Posts: 23
Joined: 2013-02-18T10:12:03-07:00
Authentication code: 6789

Re: Conversion of SVG to other formats does not correctly work

Post by canavan »

I can confirm that the current beta fixes this problem for us. Thanks.
Post Reply