Reaperxxxx commited on
Commit
f08c77b
·
verified ·
1 Parent(s): 1918801

Delete newfile.py

Browse files
Files changed (1) hide show
  1. newfile.py +0 -120
newfile.py DELETED
@@ -1,120 +0,0 @@
1
- from flask import Flask, request, jsonify, send_file
2
- import struct
3
- import re
4
- import os
5
- from io import BytesIO
6
- import requests
7
- from PIL import Image, ImageDraw, ImageFont # Pillow library for image processing
8
-
9
- app = Flask(__name__)
10
-
11
- def signed_int_to_hex(signed_int):
12
- return format(signed_int if signed_int >= 0 else signed_int + (1 << 32), '08X')[6:8] + ' ' + format(signed_int, '08X')[4:6] + ' ' + format(signed_int, '08X')[2:4] + ' ' + format(signed_int, '08X')[0:2]
13
-
14
- def signed_int_to_float(signed_int):
15
- return struct.unpack('<f', struct.pack('<i', signed_int))[0]
16
-
17
- def signed_int_to_signed_byte(signed_int):
18
- return signed_int & 0xFF if (signed_byte := signed_int & 0xFF) < 128 else signed_byte - 256
19
-
20
- def hex_to_text(hex_str):
21
- return ''.join(chr(int(pair, 16)) for pair in hex_str.split())
22
-
23
- def sanitize_text(text):
24
- return ''.join(c if 32 <= ord(c) < 127 else '�' for c in text)
25
-
26
- def search_sanitized_text(filename, sanitized_text):
27
- if not os.path.isfile(filename):
28
- return []
29
- sanitized_text_escaped = re.escape(sanitized_text)
30
- with open(filename, 'r', encoding='latin-1') as file:
31
- text = file.read()
32
- return [match for match in re.findall(sanitized_text_escaped + r'[\s\S]*?Icon_([\w_]+)', text)]
33
-
34
- def search_text(filename, text):
35
- if not os.path.isfile(filename):
36
- return []
37
- text_escaped = re.escape(text)
38
- with open(filename, 'r', encoding='latin-1') as file:
39
- text_content = file.read()
40
- results = re.findall(text_escaped + r'[\s\S]*?(Icon_[\w_]+)[\s\S]*?(T_\w+_[\w_]+)', text_content)
41
- formatted_results = [{'Icon': result[0], 'title': result[1]} for result in results]
42
- return formatted_results
43
-
44
- def add_text_to_image(image, text):
45
- """Adds transparent text to the image."""
46
- try:
47
- # Create a drawing context
48
- draw = ImageDraw.Draw(image)
49
-
50
- # استخدم الخط الافتراضي
51
- font = ImageFont.load_default()
52
-
53
- # Calculate text size and position
54
- text_bbox = draw.textbbox((0, 0), text, font=font)
55
- text_width = text_bbox[2] - text_bbox[0] # width of the text box
56
- text_height = text_bbox[3] - text_bbox[1] # height of the text box
57
-
58
- position = ((image.width - text_width) // 2, (image.height - text_height) // 2)
59
-
60
- # Add shadow effect
61
- shadow_offset = 10 # Adjust the shadow offset as needed
62
- draw.text((position[0] + shadow_offset, position[1] + shadow_offset), text, font=font, fill=(0, 0, 0, 128))
63
-
64
- # Add the main text
65
- draw.text(position, text, font=font, fill=(255, 255, 255, 255)) # White text with no transparency
66
- except Exception as e:
67
- print(f"Error adding text to image: {e}")
68
-
69
- @app.route('/library/icons', methods=['GET'])
70
- def get_icon():
71
- icon_id = request.args.get('id')
72
- if not icon_id:
73
- return jsonify({"error": "ID parameter is required"}), 400
74
-
75
- try:
76
- signed_int = int(icon_id)
77
- except ValueError:
78
- return jsonify({"error": "Invalid ID. Please enter a valid signed integer."}), 400
79
-
80
- # Change the path to the correct location of your assets.txt
81
- filename = "/root/assets.txt" # Modify with the correct path
82
- hex_value = signed_int_to_hex(signed_int)
83
- text_value = hex_to_text(hex_value)
84
- sanitized_text_value = sanitize_text(text_value)
85
-
86
- sanitized_search_results = search_sanitized_text(filename, sanitized_text_value)
87
- if not sanitized_search_results:
88
- search_results = search_text(filename, text_value)
89
- if search_results:
90
- icon_name = search_results[0]['Icon']
91
- else:
92
- return jsonify({"error": "Text not found in the file."}), 404
93
- else:
94
- icon_name = sanitized_search_results[0]
95
-
96
- image_url = f"https://freefiremobile-a.akamaihd.net/common/Local/PK/FF_UI_Icon/{icon_name}.png"
97
- response = requests.get(image_url)
98
- if response.status_code == 200:
99
- # Load the image
100
- image = Image.open(BytesIO(response.content))
101
-
102
- # Improve image quality by resizing if needed
103
- image = image.convert("RGBA") # Ensure the image is in RGBA format
104
- image = image.resize((image.width * 2, image.height * 2), Image.Resampling.LANCZOS) # Resize to improve sharpness
105
-
106
- # Add text to the image
107
- add_text_to_image(image, "3SKRMODZ")
108
-
109
- # Save the modified image to a BytesIO object
110
- img_io = BytesIO()
111
- image.save(img_io, 'PNG')
112
- img_io.seek(0)
113
-
114
- # Return the modified image
115
- return send_file(img_io, mimetype='image/png')
116
- else:
117
- return jsonify({"error": "Image not found."}), 404
118
-
119
- if __name__ == "__main__":
120
- app.run(debug=True, host='0.0.0.0', port=7860)