Does an opaque background stay opaque under a translucent overlay?
alpha_composite uses both layers' alpha values to compute the final color and opacity.
Pixel experiment and interpretation
Put translucent red over opaque blue. Both color channels survive and the output stays opaque. Reversing the layer order changes the result.
from PIL import Image
base=Image.new('RGBA',(1,1),'blue')
top=Image.new('RGBA',(1,1),(255,0,0,128))
Image.alpha_composite(base,top).getpixel((0,0))Result (128, 0, 127, 255)
中文
把半透明标注盖到不透明底图后,输出还透明吗?
alpha_composite 依据上下两层的 alpha 合成颜色与输出透明度。
像素实验与适用边界
蓝底上覆盖半透明红色,输出保留两种色分量且保持不透明。交换图层顺序会改变结果。
from PIL import Image
base=Image.new('RGBA',(1,1),'blue')
top=Image.new('RGBA',(1,1),(255,0,0,128))
Image.alpha_composite(base,top).getpixel((0,0))结果 (128, 0, 127, 255)