dalle-mini / dalle_mini /helpers.py
Pedro Cuenca
refactor: move `captioned_strip` to library.
f62b045
raw
history blame
565 Bytes
from PIL import Image, ImageDraw, ImageFont
def captioned_strip(images, caption):
increased_h = 0 if caption is None else 48
w, h = images[0].size[0], images[0].size[1]
img = Image.new("RGB", (len(images)*w, h + increased_h))
for i, img_ in enumerate(images):
img.paste(img_, (i*w, increased_h))
if caption is not None:
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/usr/share/fonts/truetype/liberation2/LiberationMono-Bold.ttf", 40)
draw.text((20, 3), caption, (255,255,255), font=font)
return img