1篇 pillow related articles

Draw transparent text on an image with python Pillow

Using tuple to set transparent color:

Examples:

from PIL import Image, ImageDraw, ImageFont

image = Image.open("spongebob.gif").convert("RGBA")
txt = Image.new('RGBA', image.size, (255,255,255,0))

font = ImageFont.truetype("impact.ttf", 25)
d = ImageDraw.Draw(txt)    

d.text((0, 0), "This text should be 5% alpha", fill=(0, 0, 0, 15), font=font)
combined = Image.alpha_composite(image, txt)    

combined.save("foo.gif")

Reference: https://pillow.readthedocs.io/en/4.2.x/reference/ImageDraw.html#example-draw-partial-opacity-text

More ~