Created
December 5, 2017 17:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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