caption/caption.py
2018-03-10 04:18:28 +01:00

27 lines
604 B
Python
Executable File

#!/usr/bin/env python3
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
img = Image.open("input.jpg")
img.thumbnail((500, 500), Image.ANTIALIAS)
margin = 30
font_size = 24
font_file = 'Verdana.ttf'
w0, h0 = img.size
w1, h1 = 2*margin + w0, 2*margin + h0 + 30
out_img = Image.new('RGB', size=(w1, h1), color=(255, 255, 255))
out_img.paste(img, (margin, margin + 30))
font = ImageFont.load_default().font
font = ImageFont.truetype(font_file, font_size)
draw = ImageDraw.Draw(out_img)
draw.text((margin, margin/2), 'Antani', (0, 0, 0), font=font)
out_img.save('output.jpg')