Write text on existing image using Python PIL - Pillow
This could be used for any image, but for the example we use this image that was created using Python:
A slightly generic script to write text in the top left corner: (Coordintates (0, 0))
examples/python/pil_write_on_image.py
from PIL import Image from PIL import ImageFont from PIL import ImageDraw import sys in_file, out_file, text = sys.argv[1:] img = Image.open(in_file) draw = ImageDraw.Draw(img) font = ImageFont.truetype('Pillow/Tests/fonts/FreeMono.ttf', 20) draw.text((0, 0), text, (255, 255, 255), font=font) img.save(out_file)
The result looks like this:
Published on 2019-04-22
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post