Skip to content

Instantly share code, notes, and snippets.

@szepnapot
Created May 20, 2017 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szepnapot/9fcdaace3937b0fe9e4fee5eb3c19448 to your computer and use it in GitHub Desktop.
Save szepnapot/9fcdaace3937b0fe9e4fee5eb3c19448 to your computer and use it in GitHub Desktop.
Write text to image
import sys
import os
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
workdir = os.path.dirname(os.path.abspath(__file__))
text = ' '.join(sys.argv[1:])
print(text)
font = ImageFont.truetype(workdir + "Roboto-Medium.ttf",25)
img = Image.new("RGBA", (400,400),(120,20,20))
draw = ImageDraw.Draw(img)
draw.text((50, 50),text,(255,255,0),font=font)
draw.chord((100, 75, 125, 100), 0, 360, fill='green')
draw.chord((75, 100, 100, 125), 0, 360, fill='blue')
draw.chord((125, 125, 150, 150), 0, 360, fill='yellow')
draw = ImageDraw.Draw(img)
img.save("test.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment