SVG to JPG conversion issue

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.

SVG to JPG conversion issue

Postby peterb001 » 2008-02-05T16:47:47+00:00

I tried converting a SVG to a JPG or PNG image but the resulting image seems to be a little off.

Here's my original SVG:
http://searchalldeals.com/drawing.svg

And this is the resulting JPG:
http://aycu03.webshots.com/image/42442/ ... 700_rs.jpg

Someone also noticed that displaying the svg with ImageMagick shows the same problems than displaying with a browser.
peterb001
 

Re: SVG to JPG conversion issue

Postby anthony » 2008-02-05T18:39:19+00:00

Looks like the SVG does not set the fill handling for its drawings. leaving this as a default.

Which SVG renderer are you using RSVG librayr, or the internal SVG to MVG converter.

See IM Examples for details
http://imagemagick.org/Usage/draw/#svg
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8722
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: SVG to JPG conversion issue

Postby peterb001 » 2008-02-06T11:49:59+00:00

It seems like ImageMagick is interpreting fill="none" as fill="#000000"

Is this a bug? or am I doing something wrong?
peterb001
 

Re: SVG to JPG conversion issue

Postby anthony » 2008-02-06T20:25:32+00:00

Not a bug in IM. It is a non-feature of JPEG.

JPEG does NOT support transparency.

You should -flatten the SVG to some -background color before saving to JPEG.

Code: Select all
convert image.svg  -background gray  -flatten  output.jpg
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8722
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: SVG to JPG conversion issue

Postby peterb001 » 2008-02-06T20:39:16+00:00

I tried converting it with PNG and GIF as well, but the results are the same.

Also, I tried:

convert drawing.svg -background gray -flatten drawing.jpg

but the 'filled' areas are still black... the background though is gray.

Anything else I can try?
peterb001
 

Re: SVG to JPG conversion issue

Postby anthony » 2008-02-07T00:04:06+00:00

It sounds like the SVG to MVG is having trouble with some of the color specifications. I would try the rsvg delegate.

IF IM is re-build on a machine with the RSVG library it uses that library instead to trying to use its built in solution.

See IM Examples
http://imagemagick.org/Usage/draw/#svg
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8722
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: SVG to JPG conversion issue

Postby peterb001 » 2008-02-07T04:11:34+00:00

Anthony, would you have a IM that uses RSVG handy? Would you be able to test a convert of my drawing.svg and see if the resulting gif has the same problem?

http://searchalldeals.com/drawing.svg

Thanks so much.
peterb001
 

Re: SVG to JPG conversion issue

Postby anthony » 2008-02-07T18:08:03+00:00

I do have Fedora 8 RPM's that I built locally. However it currently has a problem with the Ghostscript, and is build with Liquid Resize.

Actually I build new version very very regularly from the SVN development sources.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8722
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: SVG to JPG conversion issue

Postby jorlando » 2009-01-02T12:11:35+00:00

I've run into this same issue which is a show stopper.

In my My Font Image Generator (http://interactimage.com), I set up a flash overlay in a <DIV> layer directly above a text image generated by IM. This is using a little widget called InputDraw. The widget provides a transparent drawing canvas where you can freehand annotate lower layers. It outputs the markup as a full SVG file. Next, I would merge the markup with the original image in IM.

Here is an example markup SVG file with a single path:

Code: Select all
<svg viewBox="0 0 480 320" xmlns="http://www.w3.org/2000/svg" version="1.1"><g fill="none" stroke-miterlimit="6" stroke-linecap="round"><path d="M 84 44 l -1 -1 l -1 0 l -1 0 l -1 0 l -2 0 l -1 0 l -1 1 l -1 0 l -1 2 l -1 0 l 0 1 l -1 1 l 0 1 l 0 1 l 0 1 l 0 2 l 0 1 l 0 1 l 0 2 l 0 1 l 0 1 l 1 0 l 1 0 l 3 0 l 2 0 l 1 0 l 1 0 l 1 0 l 1 0 l 1 0" opacity="1" stroke="rgb(1,1,1)" stroke-width="2"/></g></svg>


The file validates successfully as SVG 1.1 at W3c

If I save the SVG and then reload it back into IM and convert to transparent PNG, it fills the path. IM interprets fill="none" as fill="black" in the above example. I can manually change the fill="" in the SVG to any color but can't get transparent.

I dont see any mention of an RSVG renderer in the report below generated with -list format | grep SVG

Code: Select all
MSVG* SVG rw+ ImageMagick's own SVG internal renderer SVG*
SVG rw+ Scalable Vector Graphics (XML 2.6.23) SVGZ*
SVG rw+ Compressed Scalable Vector Graphics (XML 2.6.23)


If I load the same SVG file into Inkscape, it renders correctly.

Next I generated a similar single-path image in Inkscape. That image is handled correctly by IM.

I took the path style instruction from the Inkscape SVG and pasted into the SVG generated by InputDraw and IM handled the original image correctly as well.

I suppose I could tweak the XML to be IM friendly before saving it but better to fix the problem.

I'm on a shared server and have no control over the ver. 6.4.1 Imagemagick installation.

I contacted the author of InputDraw but no response yet.

Any input or suggestions?

~Jeff
jorlando
 

Re: SVG to JPG conversion issue

Postby magick » 2009-01-02T14:47:36+00:00

We have a patch for this bug in ImageMagick 6.4.8-4 Beta. It will be available sometime tomorrow. Thanks for the problem report.
User avatar
magick
Site Admin
 
Posts: 9631
Joined: 2003-05-31T11:32:55+00:00

Re: SVG to JPG conversion issue

Postby jorlando » 2009-01-03T15:56:34+00:00

Great news on fixing the fill issue. If I can get my host to install the update, I'll be able to provide freehand annotation of images. Its already working but the bug keeps me from releasing the upgrade. So there will be a mashup of font images, dingbats, clipart, and freehand in an ImageMagick GUI.

I also find that when I open an SVG from Inkscape or elsewhere, that stroke opacity is not recognized. Looking into the XML shows that opacity is specified at various values between 0.0 and 1.0, IM treats them all as 1.0 opaque.

Is this related to the fill bug or something else going on?

Thx
Jeff
jorlando
 

Re: SVG to JPG conversion issue (ignore)

Postby jorlando » 2009-01-09T13:44:16+00:00

Now I see it, sorry

We have a patch for this bug in ImageMagick 6.4.8-4 Beta.



Thx
Jeff
jorlando
 

Re: SVG to JPG conversion issue

Postby jorlando » 2009-01-11T01:15:06+00:00

I tested SVG loading with 6.4.8-4 and the path fill problem mentioned above is solved. There is still an issue with stroke-opacity.

The following SVG validates with one warning about missing DOCTYPE declaration. (Does IM care?)
Code: Select all
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 320"><g fill="none" stroke-miterlimit="6" stroke-linecap="round" stroke-linejoin="round"><path d="M 236 212 l 0 -2 l 0 -4 l 0 -3 l 0 -4 l 0 -4 l 0 -4 l 1 -9 l 0 -4 l 1 -6 l 0 -4 l 1 -7 l 1 -4 l 1 -2 l 0 -2 l 0 -2 l 1 -6 l 1 -3 l 0 -1 l 1 -2 l 0 -3 l 1 -2 l 1 -1 l 2 -2 l 2 -2 l 2 -1 l 5 -3 l 3 -2 l 2 -2 l 6 -1 l 4 -1 l 2 -1 l 1 0 l 3 0 l 1 -1 l 1 0 l 2 0 l 1 0 l 1 0 l 3 0 l 3 0 l 3 0 l 5 1 l 1 1 l 1 0 l 2 1 l 11 7 l 7 3 l 3 2 l 0 1 l 1 3 l 3 6 l 2 3 l 2 5 l 1 2 l 1 4 l 0 4 l 0 1 l 0 3 l 0 4 l 0 4 l 0 3 l 0 3 l 0 4 l 0 3 l 0 3 l 0 3 l 0 2 l 0 2 l 0 5 l 0 2 l 0 2 l 0 1 l 0 1 l 0 1 l 0 1 l 0 2 l 0 1 l 0 1 l 0 1 l 0 2 l 0 1 l 0 1 l 0 1" opacity="0.55" stroke="rgb(140,99,58)" stroke-width="5"/></g></svg>

It loads to IM with stroke-opacity="1" even though opacity is set to 0.55

-If I change the opacity="0.55" to stroke-opacity="0.55", it still loads with stroke-opacity="1"
-If I change the opacity="0.55" to stroke-opacity="0.55" AND change the order it appears in the code so that stroke-opacity appears after stroke color then it works correctly.

So the following code properly renders the stroke-opacity in IM
Code: Select all
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 320"><g fill="none" stroke-miterlimit="6" stroke-linecap="round" stroke-linejoin="round"><path d="M 236 212 l 0 -2 l 0 -4 l 0 -3 l 0 -4 l 0 -4 l 0 -4 l 1 -9 l 0 -4 l 1 -6 l 0 -4 l 1 -7 l 1 -4 l 1 -2 l 0 -2 l 0 -2 l 1 -6 l 1 -3 l 0 -1 l 1 -2 l 0 -3 l 1 -2 l 1 -1 l 2 -2 l 2 -2 l 2 -1 l 5 -3 l 3 -2 l 2 -2 l 6 -1 l 4 -1 l 2 -1 l 1 0 l 3 0 l 1 -1 l 1 0 l 2 0 l 1 0 l 1 0 l 3 0 l 3 0 l 3 0 l 5 1 l 1 1 l 1 0 l 2 1 l 11 7 l 7 3 l 3 2 l 0 1 l 1 3 l 3 6 l 2 3 l 2 5 l 1 2 l 1 4 l 0 4 l 0 1 l 0 3 l 0 4 l 0 4 l 0 3 l 0 3 l 0 4 l 0 3 l 0 3 l 0 3 l 0 2 l 0 2 l 0 5 l 0 2 l 0 2 l 0 1 l 0 1 l 0 1 l 0 1 l 0 2 l 0 1 l 0 1 l 0 1 l 0 2 l 0 1 l 0 1 l 0 1"  stroke="rgb(140,99,58)" stroke-opacity="0.55" stroke-width="5"/></g></svg>


I wrote a PHP preloader fix this while processing the XML but something seems not quite right.

Jeff
jorlando
 

Re: SVG to JPG conversion issue

Postby magick » 2009-01-11T07:51:09+00:00

We have a patch for the problem you reported. Look for it in ImageMagick 6.4.8-6 Beta by sometime tomorrow. Thanks.
User avatar
magick
Site Admin
 
Posts: 9631
Joined: 2003-05-31T11:32:55+00:00

Re: SVG to JPG conversion issue

Postby abp » 2009-02-05T05:16:13+00:00

I'm having a similar problem via opacity in a SVG to PNG convertion. I'm calling:

Code: Select all
convert -alpha on -depth 8 -background none -resize 100.0%!x100.0%! a.svg b.png


The output renders semi transparency as fully opaque black several places!?!?!

Source svg:

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
 <svg version="1.0" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
    width="27px" height="27px" viewBox="0 0 27 27" enable-background="new 0 0 27 27" xml:space="preserve">
<rect x="2.008" y="0.992" opacity="0.22" width="23" height="1"/>
<rect x="3.008" y="21.992" opacity="0.22" width="21.002" height="1"/>
<rect x="2.008" y="22.992" opacity="0.2" width="23" height="1"/>
<rect x="2.008" y="23.992" opacity="0.15" width="23" height="1"/>
<rect x="1.008" y="24.992" opacity="0.08" width="25" height="1"/>
<rect x="2.008" y="1.992" opacity="0.15" width="1" height="21.002"/>
<rect x="1.008" y="1.992" opacity="0.08" width="1" height="23.002"/>
<rect x="24.008" y="1.992" opacity="0.15" width="1" height="21.002"/>
<rect x="25.008" y="1.99" opacity="0.08" width="1" height="23.002"/>
<rect x="3.008" y="1.977" opacity="0.95" fill="#FFFFFF" width="21" height="20"/>
<rect x="2.008" y="-0.008" opacity="0.95" fill="#FFFFFF" width="23" height="1"/>
<polygon opacity="0.03" points="1.008,4 1.008,25.955 26,25.955 26,3.984 27,3.984 27,27 0.008,27 0.008,4 "/>
</svg>


Any Ideas?

Thanks in advance
abp
 
Posts: 13
Joined: 2009-02-05T05:01:55+00:00

Next

Return to Bugs

Who is online

Users browsing this forum: No registered users and 4 guests