boba / utils.py
vinceL's picture
Upload 21 files
20444bb verified
import os
from PIL import Image, ImageDraw, ImageFont
def create_placeholder_images():
# Create images directory if it doesn't exist
os.makedirs("images", exist_ok=True)
# Define characters and emotions
characters = ["echidna", "platypus", "kangaroo"]
emotions = ["neutral", "happy", "sad", "surprised","angry"]
# Create a 400x400 image for each character/emotion combination
for character in characters:
for emotion in emotions:
# Create new image with white background
img = Image.new('RGB', (400, 400), 'white')
draw = ImageDraw.Draw(img)
# Add text to image
text = f"{character}\n{emotion}"
# Try to use a system font, fallback to default
try:
font = ImageFont.truetype("Arial", 40)
except:
font = ImageFont.load_default()
# Center the text
bbox = draw.textbbox((0, 0), text, font=font)
text_width = bbox[2] - bbox[0]
text_height = bbox[3] - bbox[1]
x = (400 - text_width) / 2
y = (400 - text_height) / 2
# Draw the text
draw.text((x, y), text, fill='black', font=font, align='center')
# Save the image
filename = f"images/{character}_{emotion}.png"
img.save(filename)
if __name__ == "__main__":
create_placeholder_images()