Created
July 29, 2021 21:58
-
-
Save rinfz/ca9529f3832f8e6da92dd6dcdf34363d to your computer and use it in GitHub Desktop.
watermark images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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