ImageMagick:如何将透明背景更改为颜色?

时间:2014-08-08 16:34:32

标签: image-processing imagemagick

给定具有透明背景的输入图像sample.i.png

enter image description here

如何将其背景转换为背景为sample.o.png的文件rgb(160,160,255),不透明度为100%(或1)。


使用的答案:

convert source.png -background "rgb(160,160,255)" -flatten out.png 

请点击emcconville的答案!

1 个答案:

答案 0 :(得分:6)

来自Mark Random's suggestion。使用您的颜色创建背景图像,并在其上展平源图像。

 convert -size 150x150 xc:"rgb(160,160,255)" source.png -layers flatten out.png

example

修改 如果您不想担心图像大小,只需直接更改背景。

convert source.png -background "rgb(160,160,255)" -flatten out.png 

添加-flatten以重新设置背景颜色