Page 1 of 1

Convert svg to png with transparency

Posted: 2018-06-24T02:27:31-07:00
by llwynrt
hi

I use the command

Code: Select all

convert -background none image.svg image.png
image.svg have tranparency.
I have two computers :
  • ubuntu 18.04 (64bits) with ImageMagick 6.9.7-4 Q16 x86_64 20170114
  • debian 9 (32bits) with ImageMagick 6.9.7-4 Q16 i686 20170114
on ubuntu convert keep transparency, on debian convert doesn't keep transparency, I have black background instead.

I don't understand why. Can you help me ?

Re: Convert svg to png with transparency

Posted: 2018-06-24T03:36:57-07:00
by snibgo
IM delegates the rasterizing of SVG to one of three delegates: MVG, RSVG or Inkscape. I suspect your two computers use different delegates, or different versions of the same delegate.

"-verbose" in your commands may explain. You could paste the text output here.

If your delegate is Inkscape but an old version, I suggest you upgrade.

Re: Convert svg to png with transparency

Posted: 2018-06-24T05:32:49-07:00
by llwynrt
command with -verbose :

Code: Select all

'inkscape' '/tmp/magick-30260nGw_BxVkHZ9o' --export-png='/tmp/magick-30260y_SyPYVSMGR5' --export-dpi='90,90' --export-background='rgb(0%,0%,0%)' --export-background-opacity='0' > '/tmp/magick-30260rwzjuONyUozM' 2>&1
mvg:/tmp/magick-302607fW8wIbteBht=>/tmp/magick-302607fW8wIbteBht MVG 167x204 167x204+0+0 16-bit sRGB 7.43KB 0.330u 0:00.299
cadre0044ff.svg MVG 167x204 167x204+0+0 16-bit sRGB 7.43KB 0.000u 0:00.000
cadre0044ff.svg=>test42.png MVG 167x204 167x204+0+0 16-bit sRGB 11.3KB 0.050u 0:00.060
i have inkscape on the ubuntu computer but not on the debian. when I was using debian 8, it worked.

Re: Convert svg to png with transparency

Posted: 2018-06-24T06:44:21-07:00
by snibgo
So, I suggest you install Inkscape on the debian. IM should then use Inkscape as the delegate.

Re: Convert svg to png with transparency

Posted: 2018-06-24T08:29:39-07:00
by llwynrt
install inkscape take 172M !! I just want convert a svg file in a script. is there a lighter solution ?

Re: Convert svg to png with transparency

Posted: 2018-06-24T10:20:18-07:00
by snibgo
MVG and RSVG can rasterize SVG, keeping transparent backgrounds, by using "-background None" as you have done. Perhaps you need to upgrade IM to get this. Or perhaps the SVG contains something that prevents MVG and RSVG from doing this.

Re: Convert svg to png with transparency

Posted: 2018-06-24T10:40:38-07:00
by fmw42
Perhaps you are using the internal ImageMagick MSVG/XML renderer, which on older versions of ImageMagick is not as good as Inkscape or RSVG. If so and you do not want Inkscape, then install the most current RSVG delegate into ImageMagick on both systems. You can check if you have it as a delegate using

Code: Select all

convert -version
It should list rsvg.

Re: Convert svg to png with transparency

Posted: 2018-06-29T23:39:56-07:00
by llwynrt
I finally installed inkscape, it's work. Thank you !!