gpt4 book ai didi

python - 使用 Python 图像库 (PIL),如何在另一幅图像上合成一幅带有 alpha channel 的图像?

转载 作者:太空狗 更新时间:2023-10-29 17:08:57 25 4
gpt4 key购买 nike

我有两张图片,都带有 alpha channel 。我想将一个图像放在另一个图像之上,从而产生一个带有 alpha channel 的新图像,就像它们在图层中渲染时一样。我想用 Python Imaging Library 来做这件事,但是在其他系统中的建议会很棒,即使是原始数学也会有好处;我可以使用 NumPy。

最佳答案

这似乎可以解决问题:

from PIL import Image
bottom = Image.open("a.png")
top = Image.open("b.png")

r, g, b, a = top.split()
top = Image.merge("RGB", (r, g, b))
mask = Image.merge("L", (a,))
bottom.paste(top, (0, 0), mask)
bottom.save("over.png")

关于python - 使用 Python 图像库 (PIL),如何在另一幅图像上合成一幅带有 alpha channel 的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3374878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com