Example of how to create number images from 0 to 9 with the python module Pillow. Note: the code require to download a font file size (for example here I used OpenSans-Regular.ttf):
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
# Plot question mark:
img = Image.new('RGB', (500,500), (250,250,250))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("OpenSans-Regular.ttf", 400)
draw.text((180, -30),"?",(0,0,0),font=font)
img.save('question_mark_img.jpg')
# plot digit numbers (from 0 to 9):
for i in range(10):
img = Image.new('RGB', (500,500), (250,250,250))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("OpenSans-Regular.ttf", 400)
draw.text((150, -30),str(i),(0,0,0),font=font)
img.save('digit_number_img_'+str(i)+'.jpg')
Outputs:
References
Links | Site |
---|---|
Comment ajouter du texte sur une image avec PIL | www.science-emergence.com |
pillow | pillow.readthedocs |
How to convert a PIL Image into a numpy array? | stackoverflow |
Add Text on Image using PIL | stackoverflow |
ImageFont Module | pillow.readthedocs |
.TTF File Extension | fileinfo.com |
Most Popular Fonts | fontsquirrel.com |
font | fontsquirrel |