forked from alonexhere/FREE_OUTFIT_API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
173 lines (137 loc) · 5.01 KB
/
Copy pathapp.py
File metadata and controls
173 lines (137 loc) · 5.01 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from flask import Flask, request, jsonify, send_file
import requests
from PIL import Image
from io import BytesIO
from concurrent.futures import ThreadPoolExecutor
import os
app = Flask(__name__)
executor = ThreadPoolExecutor(max_workers=10)
session = requests.Session()
# --- Configuration ---
API_KEY = "@mrshuvo" # Updated API key
BACKGROUND_FILENAME = "outfit.png"
IMAGE_TIMEOUT = 8
CANVAS_SIZE = (800, 800)
DEFAULT_UID = "533826033" # Default UID
DEFAULT_REGION = "IND" # Default region
def fetch_player_info(uid: str, region: str):
try:
url = f"https://vip-info.vercel.app/info?uid={uid}®ion={region}"
resp = session.get(url, timeout=IMAGE_TIMEOUT)
resp.raise_for_status()
return resp.json()
except:
return None
def fetch_image(url):
try:
r = session.get(url, timeout=IMAGE_TIMEOUT)
r.raise_for_status()
return Image.open(BytesIO(r.content)).convert("RGBA")
except:
return None
@app.route('/outfit-image', methods=['GET'])
def outfit_image():
# Get parameters with defaults
uid = request.args.get('uid', DEFAULT_UID)
key = request.args.get('key')
region = request.args.get('region', DEFAULT_REGION)
# Validate API key
if key != API_KEY:
return jsonify({'error': 'Invalid API key'}), 401
# Validate UID (if provided, check it's not empty)
if not uid:
return jsonify({'error': 'Missing uid'}), 400
# Fetch player data
data = fetch_player_info(uid, region)
if not data:
return jsonify({'error': 'Player not found'}), 500
outfit_ids = data.get("profileInfo", {}).get("equippedItems", []) or []
weapon_ids = data.get("playerData", {}).get("weaponSkinShows", []) or []
# ------- 7 OUTFIT SLOTS -------
required_starts = ["211", "214", "211", "203", "204", "205", "203"]
fallback_ids = [
"211000000", "214000000", "208000000",
"203000000", "204000000", "205000000",
"212000000"
]
used_ids = set()
def get_outfit(idx, code):
matched = None
for oid in outfit_ids:
s = str(oid)
if s.startswith(code) and s not in used_ids:
matched = s
used_ids.add(s)
break
if not matched:
matched = fallback_ids[idx]
return fetch_image(f"https://iconapi.wasmer.app/{matched}")
futures = [executor.submit(get_outfit, i, c) for i, c in enumerate(required_starts)]
weapon_img = None
if weapon_ids:
weapon_img = fetch_image(f"https://iconapi.wasmer.app/{weapon_ids[0]}")
# ------- Background -------
bg_path = os.path.join(os.path.dirname(__file__), BACKGROUND_FILENAME)
# Check if background file exists
if not os.path.exists(bg_path):
return jsonify({'error': 'Background image not found'}), 500
bg = Image.open(bg_path).convert("RGBA")
bg_w, bg_h = bg.size
canvas_w, canvas_h = CANVAS_SIZE
scale = max(canvas_w / bg_w, canvas_h / bg_h)
new_w = int(bg_w * scale)
new_h = int(bg_h * scale)
bg = bg.resize((new_w, new_h), Image.LANCZOS)
offset_x = (canvas_w - new_w) // 2
offset_y = (canvas_h - new_h) // 2
canvas = Image.new("RGBA", (canvas_w, canvas_h), (0, 0, 0, 255))
canvas.paste(bg, (offset_x, offset_y), bg)
# ------- Original Positions -------
positions = [
{'x': 350, 'y': 30},
{'x': 575, 'y': 130},
{'x': 665, 'y': 350},
{'x': 575, 'y': 550},
{'x': 350, 'y': 654},
{'x': 135, 'y': 570},
{'x': 135, 'y': 130},
]
# ------- Paste Outfits -------
for idx, future in enumerate(futures):
img = future.result()
if not img:
continue
paste_x = offset_x + int(positions[idx]['x'] * scale)
paste_y = offset_y + int(positions[idx]['y'] * scale)
size = int(150 * scale)
img = img.resize((size, size), Image.LANCZOS)
canvas.paste(img, (paste_x, paste_y), img)
# ------- Paste Weapon -------
if weapon_img:
size = int(150 * scale)
weapon_x = offset_x + int(60 * scale)
weapon_y = offset_y + int(350 * scale)
weapon_img = weapon_img.resize((size, size), Image.LANCZOS)
canvas.paste(weapon_img, (weapon_x, weapon_y), weapon_img)
output = BytesIO()
canvas.save(output, format='PNG')
output.seek(0)
return send_file(output, mimetype='image/png')
@app.route('/', methods=['GET'])
def home():
"""Home endpoint with API information"""
return jsonify({
'name': 'Outfit Image API',
'version': '1.0',
'endpoint': '/outfit-image',
'parameters': {
'uid': f'Player ID (default: {DEFAULT_UID})',
'key': 'API key (required)',
'region': f'Server region (default: {DEFAULT_REGION})'
},
'example': f'/outfit-image?uid={DEFAULT_UID}&key={API_KEY}®ion={DEFAULT_REGION}',
'api_key': API_KEY
})
# For local development
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)