Skip to content

Instantly share code, notes, and snippets.

@satiridev
Last active August 19, 2019 03:28
Show Gist options
  • Save satiridev/0a11c7b692f97ff08ae5038bebca8fa1 to your computer and use it in GitHub Desktop.
Save satiridev/0a11c7b692f97ff08ae5038bebca8fa1 to your computer and use it in GitHub Desktop.
create written image using truetype font in python
# from https://code-maven.com/create-images-with-python-pil-pillow
from PIL import Image, ImageDraw, ImageFont
# mode L for grayscale
img = Image.new('RGB', (100, 30), color = (73, 109, 137))
# font path
fnt = ImageFont.truetype('/Library/Fonts/Arial.ttf', 15)
d = ImageDraw.Draw(img)
d.text((10,10), "Hello world", font=fnt, fill=(255, 255, 0))
img.save('pil_text_font.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment