0

I'm using ImageMagick to convert an svg file to png but the output file shows strange black borders that the original file doesn't have. I tried to figure out which delegate that ImageMagic uses for svg conversion, which is rsvg-convert.

convert -list delegate | grep sv
svg => "rsvg-convert' -o '%o' '%i"

But the interesting thing is when I use rsvg-convert directly, the converted image looks fine without the weird black borders

The below command results in the correct png

rsvg-convert accessible.svg -o accessible.png

The below command results in a corrupted png file with black borders

convert accessible.svg accessible.png

Output using ImageMagick[output using ImageMagic]

Output using rsvg-convert[output using rsvg-convert]

This is the code of the original svg file

<svg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'>
  <title><![CDATA[accessible]]></title>
  <path d='M8,0h84c4,0,8,4,8,8v84c0,4-4,8-8,8h-84c-4,0-8-4-8-8v-84c0-4,4-8,8-8' fill='#FFF' stroke='#000' stroke-width='1' fill-rule='evenodd'/>
  <path d='M8,3h84c3,0,5,2,5,5v84c0,3-2,5-5,5h-84c-3,0-5-2-5-5v-84c0-3,2-5,5-5' fill='#003f87' fill-rule='evenodd'/>
  <path d='M72,82l-5-13l-6-12h-13h-13c0,0-1-9-1-19l-2-19l-1-3c0-4,3-7,6-7c1-1,2-1,3,0c2,0,4,1,5,3l1,4c0,2-1,4-3,6l-3,1h-1l1,15h9h10v4v3h-9h-9v1v2v2h3h22l5,12l5,13l4-2l4-1l2,5l-14,6v-1M72,82l-5-13l-6-12h-13h-13l-1-19l-2-19l-1-3c2-18,27,0,9,7h-1l1,15h9h10v4v3h-9h-9v1v2v2h3h22l5,12l5,13l4-2l4-1l2,5l-14,6v-1M66,77l-5-9c-8,35-59,5-29-20l-1-9c-40,22,5,81,35,38' fill='#FFF' fill-rule='evenodd'/>
</svg>
nqtien310
  • 227
  • 2
  • 3
  • 11
  • Kindly share your SVG original. You didn't mention your IM version. The output from `rsvg-convert` doesn't look right either? Did you try `convert -debug all ...`? See also https://stackoverflow.com/a/75344784/2836621 – Mark Setchell Mar 11 '23 at 07:58
  • @MarkSetchell, The output from rsvg-convert looks exactly the same to the original svg file. I couldn't upload the svg file here because of format restriction ( I added the xml code to the question though ) I'm using `ImageMagick 7.1.1-2 Q16-HDRI aarch64 on MacOS M1, Montery.` – nqtien310 Mar 11 '23 at 13:26
  • Try `magick -background none IMAGE.SVG result.png` – Mark Setchell Mar 11 '23 at 15:14
  • unfortunately it still produces the same output – nqtien310 Mar 11 '23 at 16:24
  • Install Inkscape and IM will use that over RSVG. Inkscape is better. – fmw42 Mar 11 '23 at 16:53

0 Answers0