from PIL import Image, ImageDraw, ImageFont import os def create_image(text, filename): # Chemin absolu vers le répertoire des assets assets_path = os.path.join('smolagent', 'ui', 'assets') # Vérifie si le répertoire existe, sinon crée-le if not os.path.exists(assets_path): os.makedirs(assets_path) # Création d'une image vide de 200x200 px avec un fond blanc img = Image.new('RGB', (200, 200), color=(255, 255, 255)) draw = ImageDraw.Draw(img) # Utilisation d'une police simple pour afficher le texte font = ImageFont.load_default() # Méthode moderne pour obtenir la taille du texte try: # Pour les versions plus récentes de PIL bbox = draw.textbbox((0, 0), text, font=font) text_width = bbox[2] - bbox[0] text_height = bbox[3] - bbox[1] except AttributeError: # Fallback pour les anciennes versions text_width, text_height = draw.textsize(text, font) # Position du texte au centre de l'image text_position = ((200 - text_width) / 2, (200 - text_height) / 2) draw.text(text_position, text, fill=(0, 0, 0), font=font) # Sauvegarde de l'image dans le bon répertoire full_path = os.path.join(assets_path, filename) img.save(full_path) print(f"Image créée: {full_path}") # Création des images pour "user.png" et "bot.png" create_image('User', 'user.png') create_image('Bot', 'bot.png')