Backend sketch
This commit is contained in:
parent
3fb6bc40aa
commit
0c89e4ee8d
BIN
Verdana.ttf
Normal file
BIN
Verdana.ttf
Normal file
Binary file not shown.
26
caption.py
Executable file
26
caption.py
Executable file
|
@ -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')
|
Loading…
Reference in New Issue
Block a user