I try to put a transparent logo on the photo with Pillow:
# 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)
Initially my watermark has a full-transparent background. But I have a result with black half-transparent background on all image size. What am I doing wrong?
I've resolved a problem with this:
image = Image.open(photo_image_path).convert('RGBA')
watermark = Image.open(watermark_image_path).convert('RGBA')
layer = Image.new('RGBA', image.size, (0, 0, 0, 0))
layer.paste(watermark, (x, y))
# Create a copy of the layer
layer2 = layer.copy()
# Put alpha on the copy
layer2.putalpha(128)
# merge layers with mask
layer.paste(layer2, layer)
result = Image.alpha_composite(image, layer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With