Convert svg to png with transparency

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
llwynrt
Posts: 4
Joined: 2018-06-24T02:15:51-07:00
Authentication code: 1152

Convert svg to png with transparency

Post by llwynrt » 2018-06-24T02:27:31-07:00

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 ?

snibgo
Posts: 10978
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert svg to png with transparency

Post by snibgo » 2018-06-24T03:36:57-07:00

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.
snibgo's IM pages: im.snibgo.com

User avatar
llwynrt
Posts: 4
Joined: 2018-06-24T02:15:51-07:00
Authentication code: 1152

Re: Convert svg to png with transparency

Post by llwynrt » 2018-06-24T05:32:49-07:00

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.

snibgo
Posts: 10978
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert svg to png with transparency

Post by snibgo » 2018-06-24T06:44:21-07:00

So, I suggest you install Inkscape on the debian. IM should then use Inkscape as the delegate.
snibgo's IM pages: im.snibgo.com

User avatar
llwynrt
Posts: 4
Joined: 2018-06-24T02:15:51-07:00
Authentication code: 1152

Re: Convert svg to png with transparency

Post by llwynrt » 2018-06-24T08:29:39-07:00

install inkscape take 172M !! I just want convert a svg file in a script. is there a lighter solution ?

snibgo
Posts: 10978
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert svg to png with transparency

Post by snibgo » 2018-06-24T10:20:18-07:00

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.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 24155
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert svg to png with transparency

Post by fmw42 » 2018-06-24T10:40:38-07:00

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.

User avatar
llwynrt
Posts: 4
Joined: 2018-06-24T02:15:51-07:00
Authentication code: 1152

Re: Convert svg to png with transparency

Post by llwynrt » 2018-06-29T23:39:56-07:00

I finally installed inkscape, it's work. Thank you !!

Post Reply