Skip to content

Instantly share code, notes, and snippets.

@tzookb
Created June 5, 2023 01:03
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 tzookb/b5d3aa46bc5893f92019de37810c57d0 to your computer and use it in GitHub Desktop.
Save tzookb/b5d3aa46bc5893f92019de37810c57d0 to your computer and use it in GitHub Desktop.
create icons with letters AA, AB, ..., ZZ
from PIL import Image, ImageDraw, ImageFont
# Create a blank image with a white background
width, height = 60, 60
background_color = (255, 255, 255) # White
image = Image.new("RGB", (width, height), background_color)
# Create a draw object
draw = ImageDraw.Draw(image)
# Specify the font and size
font_size = 40
font_path = "Caveat-VariableFont_wght.ttf" # Replace with the path to the Arial font file
font = ImageFont.truetype(font_path, font_size)
# Set the text color
text_color = (0, 0, 0) # Black
# Loop through each variation of two letters
for i in range(26):
for j in range(26):
letter1 = chr(ord('A') + i)
letter2 = chr(ord('A') + j)
text1_width, text1_height = draw.textsize(letter1, font=font)
text2_width, text2_height = draw.textsize(letter2, font=font)
total_width = text1_width + text2_width
total_height = max(text1_height, text2_height)
position = ((width - total_width) // 2, (height - total_height) // 2)
# Draw the letters on the image
draw.text(position, letter1 + letter2, font=font, fill=text_color)
# Save the image with the corresponding letters as the filename
filename = f"letters/{letter1.lower()}{letter2.lower()}.png"
image.save(filename)
# Clear the image for the next iteration
draw.rectangle((0, 0, width, height), fill=background_color)
print("Icon images created successfully.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment