Reaperxxxx commited on
Commit
dc4c109
·
verified ·
1 Parent(s): ac723d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -4
app.py CHANGED
@@ -3,6 +3,7 @@ from PIL import Image, ImageDraw, ImageFont
3
  import urllib.parse
4
  import uuid
5
  import os
 
6
 
7
  app = Flask(__name__)
8
 
@@ -30,13 +31,9 @@ def leaderboard(names):
30
  img_width, img_height = bg.size
31
 
32
  # Determine spacing based on the number of names
33
- total_names = len(name_list)
34
  max_names = 10
35
-
36
- # Consistent spacing for all cases
37
  start_y = 87 # Fixed starting Y position
38
  line_spacing = (img_height - 300) // max_names # Uniform spacing
39
-
40
  start_x = img_width - 680 # Adjust horizontal alignment
41
 
42
  # Draw names on image
@@ -56,5 +53,50 @@ def leaderboard(names):
56
 
57
  return send_file(output_path, mimetype='image/png')
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  if __name__ == '__main__':
60
  app.run(host="0.0.0.0", port=7860, debug=True)
 
3
  import urllib.parse
4
  import uuid
5
  import os
6
+ import re
7
 
8
  app = Flask(__name__)
9
 
 
31
  img_width, img_height = bg.size
32
 
33
  # Determine spacing based on the number of names
 
34
  max_names = 10
 
 
35
  start_y = 87 # Fixed starting Y position
36
  line_spacing = (img_height - 300) // max_names # Uniform spacing
 
37
  start_x = img_width - 680 # Adjust horizontal alignment
38
 
39
  # Draw names on image
 
53
 
54
  return send_file(output_path, mimetype='image/png')
55
 
56
+ @app.route('/userinfo/<path:data>')
57
+ def userinfo(data):
58
+ # Decode URL-encoded data
59
+ decoded_data = urllib.parse.unquote(data)
60
+
61
+ # Extract information using regex (Format: Name-XP-Level-Royalties)
62
+ match = re.match(r'(.+?)-(\d+/\d+)xp-level (\d+)-Royalties (\d+)', decoded_data)
63
+ if not match:
64
+ return "Error: Invalid format. Expected format - 'Full Name-X/Xxp-level Y-Royalties Z'", 400
65
+
66
+ full_name, xp, level, royalties = match.groups()
67
+
68
+ # Load background image
69
+ bg = Image.open("profile_bg.png").convert("RGBA")
70
+ draw = ImageDraw.Draw(bg)
71
+
72
+ # Load font (Ensure the font file exists in the project directory)
73
+ font_path = "gagalin.otf"
74
+ if not os.path.exists(font_path):
75
+ return "Error: Font file 'Gagalin.otf' not found", 500
76
+
77
+ font = ImageFont.truetype(font_path, 40) # Adjust font size as needed
78
+
79
+ # Text positions
80
+ start_x = 50
81
+ start_y = 100
82
+
83
+ # Draw text
84
+ draw.text((start_x, start_y), f"Name: {full_name}", font=font, fill="white")
85
+ draw.text((start_x, start_y + 70), f"XP: {xp}", font=font, fill="white")
86
+ draw.text((start_x, start_y + 140), f"Level: {level}", font=font, fill="white")
87
+ draw.text((start_x, start_y + 210), f"Royalties: {royalties}", font=font, fill="white")
88
+
89
+ # Generate unique filename
90
+ output_filename = f"output_{uuid.uuid4().hex}.png"
91
+ output_path = os.path.join("output", output_filename)
92
+
93
+ # Ensure output directory exists
94
+ os.makedirs("output", exist_ok=True)
95
+
96
+ # Save the generated image
97
+ bg.save(output_path)
98
+
99
+ return send_file(output_path, mimetype='image/png')
100
+
101
  if __name__ == '__main__':
102
  app.run(host="0.0.0.0", port=7860, debug=True)