python PIL-检查图像是否透明 [英] python PIL - check if image is transparent
本文介绍了python PIL-检查图像是否透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am pasting an image on another image, and after looking at this question, I saw that in order to paste a transparent image, you need to do
background = Image.open("test1.png")
foreground = Image.open("test2.png")
background.paste(foreground, (0, 0), foreground)
使用正常图片,您应该
background = Image.open("test1.png")
foreground = Image.open("test2.png")
background.paste(foreground, (0, 0)) // difference here
我的问题是,如何检查图像是否透明,以便确定如何使用paste
方法(带有或不带有最后一个参数).
my question is, how can I check if an image it transparent so I can determine how to use the paste
method (with or without the last parameter).
推荐答案
检查图像的模式以获取alpha透明层.例如,RGB没有透明度,但是RGBA有透明度.
Check the mode of the image for an alpha transparency layer. For example, RGB has no transparency, but RGBA does.
请参见 https://pillow.readthedocs.io/en/latest/请参阅handbook/concepts.html .
这篇关于python PIL-检查图像是否透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文