2010-11-10 44 views
2

我尝试将SVG转换为PNG。结果图片有白色背景我需要透明。SVG到PNG由PythonMagickWand

示例代码:

wand = NewMagickWand() 
MagickReadImage(wand,tmp_file_name) 
transparentColor = NewPixelWand() 
PixelSetMagickColor(transparentColor, 'none') 
MagickSetBackgroundColor(wand, transparentColor) 
MagickWriteImage(wand,new_filename) 

,如果我在命令行做:

convert -background 'transparent' ./media/2222222.svg ./media/2222222.png 

我有一个透明的图片。

+0

你尝试'PixelSetMagickColor(transparentColor, '白')'什么? – nmichaels 2010-11-10 21:25:26

+0

我做了同样的结果,背景是白色的。 – mapcuk 2010-11-10 22:54:53

回答

2

我用子,我得到了我想要

args = ['convert', '-background', 'transparent', './media/2222222.svg', './media/2222222.png',] 
result = subprocess.call(args) 
+0

@macpuk:你能提供更多关于你如何实现子进程的代码吗?你用过MagickCommandGenesis()吗? – fuzz 2011-09-21 05:07:45