Nishant Shrivastava
Nishant Shrivastava

Reputation: 2119

Image Magick not converting svg file to jpg

I am using Image Magick library to convert a .svg file into a jpg but it is creating a blank image. I have checked a lot of forums for it , but was not able to figure out the problem with it. I have a file name abc.svg , which have the following code inside it;

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" width="12cm" height="12cm">
<g style="fill-opacity:0.7; stroke:black; stroke-width:0.1cm;">
<circle cx="6cm" cy="2cm" r="100" style="fill:red;"transform="translate(0,50)" /> 
<circle cx="6cm" cy="2cm" r="100" style="fill:blue;"transform="translate(70,150)" />
<circle cx="6cm" cy="2cm" r="100" style="fill:green;"transform="translate(-70,150)"/>
 </g>
</svg>

I am trying to convert it by the following command :

$convert abc.svg abc.jpg

But the file I am getting (i.e abc.jpg is simply blank)

Please help me out with the problem, so that I can move ahead with the thing.

Thanks in advance.

Upvotes: 0

Views: 1516

Answers (2)

Anomie
Anomie

Reputation: 94794

For one thing, your SVG file has errors. You are missing a space before the transform attribute in your three circles. It converts fine for me with ImageMagick (6.6.9-7 from Debian) after I fix that.

But when I try your file in ImageMagick, it doesn't give me an empty file. It gives a few errors and no output file at all. Does your SVG file work in any other program, e.g. Inkscape? Does your copy of ImageMagick handle other SVG files?

Upvotes: 0

Michael Berkowski
Michael Berkowski

Reputation: 270609

This is possibly because JPEG does not support transparency, and is misinterpreting the SVG opacity. According to this post on the ImageMagick forums, you could try to first flatten the SVG with a background color and then convert it to JPEG.

convert image.svg  -background gray  -flatten  output.jpg
convert abc.svg abc.jpg

Upvotes: 2

Related Questions