File size: 3,414 Bytes
d571fc7
f33e423
 
 
 
dc4c109
f33e423
 
 
 
 
 
 
d571fc7
f33e423
d571fc7
 
f33e423
 
 
 
 
d571fc7
 
 
 
f33e423
4b11785
d571fc7
 
 
 
 
 
ac723d6
 
4ca8f9b
f33e423
 
d571fc7
 
 
f33e423
 
 
 
 
 
 
 
 
 
 
 
 
dc4c109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f33e423
378dcf2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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):
    # 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/<path:data>')
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)