from flask import Flask, send_file from PIL import Image, ImageDraw, ImageFont import urllib.parse import uuid import os import re app = Flask(__name__) @app.route('/leaderboard/') def leaderboard(names): # Decode URL-encoded names (handling spaces) decoded_names = urllib.parse.unquote(names) name_list = [name.strip() for name in decoded_names.split('-') if name.strip()] if len(name_list) == 0: return "Error: At least 1 name required", 400 # Load background image bg = Image.open("image.png").convert("RGBA") draw = ImageDraw.Draw(bg) # Load Gagalin font (Ensure the font file exists in the project directory) font_path = "gagalin.otf" if not os.path.exists(font_path): return "Error: Font file 'Gagalin.otf' not found", 500 font = ImageFont.truetype(font_path, 36) # Adjust font size as needed # Image dimensions img_width, img_height = bg.size # Determine spacing based on the number of names max_names = 10 start_y = 87 # Fixed starting Y position line_spacing = (img_height - 300) // max_names # Uniform spacing start_x = img_width - 680 # Adjust horizontal alignment # Draw names on image for i, name in enumerate(name_list[:max_names]): position = (start_x, start_y + i * line_spacing) draw.text(position, f"{i+1}. {name}", font=font, fill="white") # Generate unique filename output_filename = f"output_{uuid.uuid4().hex}.png" output_path = os.path.join("output", output_filename) # Ensure output directory exists os.makedirs("output", exist_ok=True) # Save the generated image bg.save(output_path) return send_file(output_path, mimetype='image/png') @app.route('/userinfo/') def userinfo(data): # Decode URL-encoded data decoded_data = urllib.parse.unquote(data) # Extract information using regex (Format: Name-XP-Level-Royalties) match = re.match(r'(.+?)-(\d+/\d+)xp-level (\d+)-Royalties (\d+)', decoded_data) if not match: return "Error: Invalid format. Expected format - 'Full Name-X/Xxp-level Y-Royalties Z'", 400 full_name, xp, level, royalties = match.groups() # Load background image bg = Image.open("profile_bg.png").convert("RGBA") draw = ImageDraw.Draw(bg) # Load font (Ensure the font file exists in the project directory) font_path = "gagalin.otf" if not os.path.exists(font_path): return "Error: Font file 'Gagalin.otf' not found", 500 font = ImageFont.truetype(font_path, 40) # Adjust font size as needed # Text positions start_x = 50 start_y = 100 # Draw text draw.text((start_x, start_y), f"Name: {full_name}", font=font, fill="white") draw.text((start_x, start_y + 70), f"XP: {xp}", font=font, fill="white") draw.text((start_x, start_y + 140), f"Level: {level}", font=font, fill="white") draw.text((start_x, start_y + 210), f"Royalties: {royalties}", font=font, fill="white") # Generate unique filename output_filename = f"output_{uuid.uuid4().hex}.png" output_path = os.path.join("output", output_filename) # Ensure output directory exists os.makedirs("output", exist_ok=True) # Save the generated image bg.save(output_path) return send_file(output_path, mimetype='image/png') if __name__ == '__main__': app.run(host="0.0.0.0", port=7860, debug=True)