Skip to content

Instantly share code, notes, and snippets.

@esmitt
Created December 5, 2017 17:04
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 esmitt/d61f8734516b7de986f6ef39794b774e to your computer and use it in GitHub Desktop.
Save esmitt/d61f8734516b7de986f6ef39794b774e to your computer and use it in GitHub Desktop.
Generates a single image with white background with a word (for testing purposes) using PIL
from PIL import Image, ImageDraw, ImageFont
from random import randint
text = 'pendejo'
nimages = 20
folder = 'output/'
sizeX = 600
sizeY = 200
image = Image.new("RGBA", (600,150), (255,255,255))
font = ImageFont.truetype("micross.ttf", 64) ##this font is required of course
size = ImageFont.truetype("micross.ttf", 64)
bound = size.getsize(text)
for x in range(0, nimages):
image = Image.new("RGBA", (sizeX, sizeY), (255,255,255))
draw = ImageDraw.Draw(image)
posX = randint(0, sizeX - bound[0])
posY = randint(0, sizeY - bound[1])
draw.text((posX, posY), text, (0,0,0), font=font)
image.save(folder+'output'+str(x)+'.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment