Skip to content

Instantly share code, notes, and snippets.

@spacekitcat
Created May 30, 2020 12:37
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 spacekitcat/04722b037e85c1331fe1ca228627ddd1 to your computer and use it in GitHub Desktop.
Save spacekitcat/04722b037e85c1331fe1ca228627ddd1 to your computer and use it in GitHub Desktop.
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import os
# The range of images to generate, which also controls the number of gradient 'stops'
imageCount = 30
# How far to increment red for each image, currently tied to imageCount as you can see
colorIncrement = 255 / imageCount
# Output folder for the images
outputDir = "output"
# Path to a TTF
trueTypeFontPath = "VT323-Regular.ttf"
if not os.path.exists(outputDir):
os.mkdir(outputDir)
currentColor = 20
for x in range(imageCount):
img = Image.new('RGB', (32, 32), (int(currentColor), 0, 0))
currentColor += colorIncrement
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(trueTypeFontPath, 32)
draw.text((0, 0), str(x),(255,255,255),font=font)
img.save(outputDir + "/" + str(x) + ".png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment