如何为透明的 PNG 文件添加背景? [英] How to add a background to a transparent PNG file?

查看:160
本文介绍了如何为透明的 PNG 文件添加背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ImageMagick 将 PNG 文件作为背景添加到具有透明区域的 PNG 图像,如下所示:

I'm trying to add a PNG file as background to an PNG image with transparent regions using ImageMagick like so:

convert input.png -texture bg.png output.png

我还没有弄清楚如何将我的背景填充到 100% 宽度/高度,因为上面的例子不起作用.我最终得到的是透明的同一个文件,我不知道为什么.

I'm not so far to find out how to fill my background to 100% width / height, because the above example does not work. I end up with the same file that is transparent and I don't know why.

如何应用在整个文件中使用全宽/全高的背景?(最好使用cover方法,意思是保持背景的纵横比和切割重叠)

How can I apply a background that uses full width/height across the whole file? (Preferable using the cover method, meaning to keep aspect ratio of the background and cutting overlaps)

推荐答案

如果您想在 Unix 上平铺背景,请尝试

If you want to tile out the background then on Unix, try

convert input.png \( +clone -tile bg.png -draw "color 0,0 reset" \) +swap -compose over -composite output.png

在 Windows 上:

On Windows:

convert input.png ( +clone -tile bg.png -draw "color 0,0 reset" ) +swap -compose over -composite output.png

如果你只是想调整背景大小,那么在 Unix 上试试

If you just want to resize the background, then on Unix try

dims=$( convert input.png -format "%wx%h" info: )
convert input.png \( bg.png -resize $dims +repage \) +swap -compose over -composite output.png

我不太了解 Windows 告诉你如何做变量

I do not know Windows that well to tell you how to do the variable

在 ImageMagick 7 上,在 Unix 中,您可以更轻松地做到:

On ImageMagick 7, in Unix, you can do it easier as:

magick input.png -set option:dims "%wx%h" \( bg.png -resize "%[dims]" \) +swap -compose over -composite output.png

或在 Windows 中:

Or in Windows:

magick input.png -set option:dims "%wx%h" ( bg.png -resize "%[dims]" ) +swap -compose over -composite output.png

这篇关于如何为透明的 PNG 文件添加背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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