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.
peterb001

SVG to JPG conversion issue

Post by peterb001 »

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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG to JPG conversion issue

Post by anthony »

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
https://imagemagick.org/Usage/
peterb001

Re: SVG to JPG conversion issue

Post by peterb001 »

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

Is this a bug? or am I doing something wrong?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG to JPG conversion issue

Post by anthony »

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
https://imagemagick.org/Usage/
peterb001

Re: SVG to JPG conversion issue

Post by peterb001 »

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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG to JPG conversion issue

Post by anthony »

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
https://imagemagick.org/Usage/
peterb001

Re: SVG to JPG conversion issue

Post by peterb001 »

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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG to JPG conversion issue

Post by anthony »

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
https://imagemagick.org/Usage/
jorlando

Re: SVG to JPG conversion issue

Post by jorlando »

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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: SVG to JPG conversion issue

Post by magick »

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.
jorlando

Re: SVG to JPG conversion issue

Post by jorlando »

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)

Post by jorlando »

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

Post by jorlando »

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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: SVG to JPG conversion issue

Post by magick »

We have a patch for the problem you reported. Look for it in ImageMagick 6.4.8-6 Beta by sometime tomorrow. Thanks.
abp

Re: SVG to JPG conversion issue

Post by abp »

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