Skip to content

Instantly share code, notes, and snippets.

@rinfz
Created July 29, 2021 21:58
Show Gist options
  • Save rinfz/ca9529f3832f8e6da92dd6dcdf34363d to your computer and use it in GitHub Desktop.
Save rinfz/ca9529f3832f8e6da92dd6dcdf34363d to your computer and use it in GitHub Desktop.
watermark images
from PIL import Image, ImageDraw, ImageFont
with Image.open("img.jpeg").convert("RGBA") as base:
font_size = 100
txt = Image.new("RGBA", base.size, (255, 255, 255, 0))
fnt = ImageFont.truetype("/home/mar/.fonts/FiraMono-Regular.ttf", font_size)
d = ImageDraw.Draw(txt)
d.text(
(10, base.size[1] - font_size - 10),
"Watermark Text",
font=fnt,
fill=(255, 255, 255, 128),
)
out = Image.alpha_composite(base, txt)
out = out.convert("RGB")
out.save("img_w.jpeg", optimize=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment