使用ImageMagick(bakground透明或白色)的圆角 [英] Rounded corners using ImageMagick (bakground transparent or white)

查看:770
本文介绍了使用ImageMagick(bakground透明或白色)的圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ImageMagick为我的图像添加圆角。

I'm trying to add rounded corners to my images using ImageMagick.

如果输入图像是PNG或GIF文件,我的脚本工作正常。

If the input image is a PNG or GIF file my script is working correctly.

但是如果我的输入文件是JPEG文件,那么角落是黑色的。我想在这种情况下使用自定义角落颜色(例如白色)任何想法?

But if my input file is a JPEG file, the corners are black. I'd like to use a custom corner color in that case (ex. white) any idea ?

这是我的工作bash脚本:

Here's my working bash script :

convert -size "$W"x"$H" xc:none -draw "roundrectangle 0,0,$W,$H,$R,$R" $MASK
convert $SRC -matte $MASK -compose DstIn -composite $DST

参数是:

$ SRC:输入图像
$ W:输入图像的宽度
$ H:输入图像的高度
$ MASK:包含透明角落的蒙版图像
$ DST:带圆角的结果图像。

$SRC : the input image $W : width of input image $H : height of input image $MASK : the mask image which contains transparent corners $DST : the resulting image with rounded corners.

提前致谢。

推荐答案

终于找到了解决方案:

convert -size "$W"x"$H" xc:none -draw "roundrectangle 0,0,$W,$H,$R,$R" $MASK
convert $SRC -matte $MASK -compose DstIn -composite $TMP_PNG

我正在使用临时PNG文件作为目的地。如果输出格式不是GIF或PNG,我使用ImageMagick的flatten功能,白色作为背景。

I'm using a "temp" PNG file as destination. If the output format is not GIF or PNG, I use the "flatten" function of ImageMagick with the white color as background.

convert $TMP_PNG -background white -flatten $DST

对于PNG输出:只需将$ TMP_PNG复制到$ DST

For PNG output : simply copy $TMP_PNG to $DST

对于GIF输出:只需将$ TMP_PNG转换为$ DST

For GIF output : simply convert $TMP_PNG to $DST

否则:如前所述展平图像。

Else : flatten the image as said before.

希望有所帮助。

这篇关于使用ImageMagick(bakground透明或白色)的圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆