diff --git a/Verdana.ttf b/Verdana.ttf new file mode 100644 index 0000000..e6f57d3 Binary files /dev/null and b/Verdana.ttf differ diff --git a/caption.py b/caption.py new file mode 100755 index 0000000..2297e78 --- /dev/null +++ b/caption.py @@ -0,0 +1,26 @@ +#!/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')