| 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/<path:names>') |
| def leaderboard(names): |
| |
| 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 |
|
|
| |
| bg = Image.open("image.png").convert("RGBA") |
| draw = ImageDraw.Draw(bg) |
|
|
| |
| 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) |
|
|
| |
| img_width, img_height = bg.size |
|
|
| |
| max_names = 10 |
| start_y = 87 |
| line_spacing = (img_height - 300) // max_names |
| start_x = img_width - 680 |
|
|
| |
| 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") |
|
|
| |
| output_filename = f"output_{uuid.uuid4().hex}.png" |
| output_path = os.path.join("output", output_filename) |
|
|
| |
| os.makedirs("output", exist_ok=True) |
|
|
| |
| bg.save(output_path) |
|
|
| return send_file(output_path, mimetype='image/png') |
|
|
| @app.route('/userinfo/<path:data>') |
| def userinfo(data): |
| |
| decoded_data = urllib.parse.unquote(data) |
|
|
| |
| 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() |
|
|
| |
| bg = Image.open("profile_bg.png").convert("RGBA") |
| draw = ImageDraw.Draw(bg) |
|
|
| |
| 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) |
|
|
| |
| start_x = 50 |
| start_y = 100 |
|
|
| |
| 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") |
|
|
| |
| output_filename = f"output_{uuid.uuid4().hex}.png" |
| output_path = os.path.join("output", output_filename) |
|
|
| |
| os.makedirs("output", exist_ok=True) |
|
|
| |
| 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) |