Initial commit: bot Discord Vicy V1.8
This commit is contained in:
commit
56958c5832
70 changed files with 8469 additions and 0 deletions
50
utils/image_generator.py
Normal file
50
utils/image_generator.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import json
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import os
|
||||
|
||||
def generate_bank_image(user_id, balance, transactions):
|
||||
"""Génère une image avec les informations bancaires de l'utilisateur."""
|
||||
|
||||
image_path = "ressources/assets/template.png"
|
||||
if not os.path.exists(image_path):
|
||||
print(f"❌ Erreur : Fichier {image_path} introuvable.")
|
||||
return None
|
||||
|
||||
image = Image.open(image_path)
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
||||
# Vérifier que la police existe
|
||||
font_path = "ressources/font.ttf"
|
||||
if not os.path.exists(font_path):
|
||||
print("❌ Erreur : Police introuvable, chargement de la police par défaut.")
|
||||
font_large = ImageFont.load_default()
|
||||
font_small = ImageFont.load_default()
|
||||
else:
|
||||
font_large = ImageFont.truetype(font_path, 120)
|
||||
font_small = ImageFont.truetype(font_path, 30)
|
||||
|
||||
# Centrer le solde en dessous de la fenêtre bleue
|
||||
balance_text = f"Solde : {balance} €"
|
||||
balance_x = (image.width - draw.textlength(balance_text, font=font_large)) // 2
|
||||
balance_y = 850 # Ajustez cette valeur pour positionner le texte en dessous de la fenêtre bleue
|
||||
draw.text((balance_x, balance_y), balance_text, fill="white", font=font_large)
|
||||
|
||||
# Affichage des transactions
|
||||
start_x = 50 # Ajustez cette valeur pour l'alignement horizontal
|
||||
start_y = 400 # Ajustez cette valeur pour l'alignement vertical
|
||||
spacing_y = 60 # Espace entre les lignes de transaction
|
||||
|
||||
for transaction in transactions[:3]: # Max 3 transactions
|
||||
transaction_text = f"{transaction['date']} - {transaction['type']} : {transaction['montant']}€"
|
||||
draw.text((start_x, start_y), transaction_text, fill="black", font=font_small)
|
||||
start_y += spacing_y
|
||||
|
||||
# Supprimer le texte "Victoria’s Vice™"
|
||||
erase_box = (30, image.height - 50, 250, image.height - 20)
|
||||
draw.rectangle(erase_box, fill=(255, 255, 255))
|
||||
|
||||
# Sauvegarde de l'image générée
|
||||
output_path = f"ressources/bank_{user_id}.png"
|
||||
image.save(output_path)
|
||||
print(f"✅ Image bancaire générée : {output_path}")
|
||||
return output_path
|
||||
Loading…
Add table
Add a link
Reference in a new issue