我尝试使用Pillow将透明的Logo放在照片上:
# First, I convert my photo and watermark to RGBA:
image = Image.open(photo_image_path).convert('RGBA')
watermark = Image.open(watermark_image_path).convert('RGBA')
# then I сreate an empty layer with the same size as image
# and put watermark in x/y position
layer = Image.new('RGBA', image.size, (0, 0, 0, 0))
layer.paste(watermark, (x, y))
# then add transparency
layer.putalpha(128)
# and merge image with logo
result = Image.alpha_composite(image, layer)
一开始我的水印背景是完全透明的。但是我在所有图像尺寸上都得到了一个黑色半透明的背景。我错在哪里了?