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

Re: SVG to JPG conversion issue

Post by magick »

Try this command:
  • convert -stroke white a.svg -depth 8 b.png
abp

Re: SVG to JPG conversion issue

Post by abp »

Try this command:

convert -stroke white a.svg -depth 8 b.png
It works! But sadly only for the single image. The other SVGs containing semi-transparency in the batch I'm trying to process contains heaps of artifacts after using the -stroke parameter. Is there a more general approach I can take to fix the issue? Is my problem something that will be accommodated in future imagemagick releases?

Thanks for you time
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 »

abp wrote: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!?!?!
I tried this with my RSVG version of ImageMagick (latest version), but I cleaned up your command so that the order made sense. The -resize does nothing, and the depth is not needed. Added a -density to see a enlarged rendering.

Code: Select all

convert -density 300 -background none a.svg b.png
Result was fine. semi-transparency was good. no black background.

Changing this to use the internal MSVG method...

Code: Select all

convert -density 300 -background none MSVG:a.svg  b.png
that also worked though the semi-transparency did not shade properly (understandable as it is incomplete) but it came out quite well.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
abp

Re: SVG to JPG conversion issue

Post by abp »

I tried this with my RSVG version of ImageMagick (latest version), but I cleaned up your command so that the order made sense. The -resize does nothing, and the depth is not needed. Added a -density to see a enlarged rendering.

Code:
convert -density 300 -background none a.svg b.png


Result was fine. semi-transparency was good. no black background.
Tried your approach but still get artifacts. Using the below source and getting below results.

Source:

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.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_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.0039063" y="0.9941406" opacity="0.22" width="23" height="1"/>
<rect x="3.0039063" y="21.9941406" opacity="0.22" width="21.0019531" height="1"/>
<rect x="2.0043945" y="22.9941406" opacity="0.2" width="23.0004883" height="1"/>
<rect x="2.0043945" y="23.9941406" opacity="0.15" width="23.0004883" height="1"/>
<rect x="1.0043945" y="24.9941406" opacity="0.08" width="25.0004883" height="1"/>
<rect x="2.0039063" y="1.9941406" opacity="0.15" width="1" height="21.0019531"/>
<rect x="1.0039063" y="1.9941406" opacity="0.08" width="1" height="23.0019531"/>
<rect x="24.0039063" y="1.9941406" opacity="0.15" width="1" height="21.0019531"/>
<rect x="25.0039063" y="1.9921875" opacity="0.08" width="1" height="23.0019531"/>
<rect x="3.0039063" y="1.9785156" opacity="0.95" fill="#FFFFFF" width="21" height="20"/>
<rect x="2.0039063" y="-0.0058594" opacity="0.03" width="23" height="1"/>
<polygon opacity="0.03" points="1.0039063,4.0019531 1.0039063,25.9570313 25.9960938,25.9570313 25.9960938,3.9863281 
	26.9960938,3.9863281 26.9960938,27.0019531 0.0039063,27.0019531 0.0039063,4.0019531 "/>
</svg>
Should look like:
Image

Looks like (with latest imagemagick v.6.4.9-2-Q16)
Image

Seems like the semitransparent anti aliasing pixels of the separate <rect> elements are overlapping resulting in 'dark' areas. Maybe a simple alpha blending problem?

Any ideas?
abp

Re: SVG to JPG conversion issue

Post by abp »

ImageMagic version ImageMagick-6.4.9-4 solved the problem, Thanks
Post Reply