jjzjj

python PIL : Blend transparent image onto another

coder 2023-08-25 原文

我需要使用 Python 的 PIL 库将一个图像混合到另一个图像上。

如下图所示,我的两个源图像是 A 和 B。 当我这样做时:

imageA.paste(imageB, (0, 0), imageB)

结果我得到了 C,但是灰色背景顶部的部分现在是透明的。图片 D 是我在 Photoshop 中将 B 放在 A 上时得到的结果,也是我需要使用 PIL 实现的结果。

我做错了什么?我如何在 PIL 中组合 B over A 以获得 D 而不是 C?

最佳答案

使用 RGBA 作为透明蒙版

imageA.paste(imageB, (0, 0), imageB.convert('RGBA'))

关于 python PIL : Blend transparent image onto another,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24544414/

有关python PIL : Blend transparent image onto another的更多相关文章

随机推荐