-
Notifications
You must be signed in to change notification settings - Fork 0
/
high.py
52 lines (44 loc) · 1.93 KB
/
high.py
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
import os
import time
from PIL import Image
factor = 3.2
rate = 50
os.makedirs("/tmp/output", exist_ok=True)
for filename in os.listdir("/tmp/input"):
image_path = os.path.join("/tmp/input", filename)
if os.path.isfile(image_path):
image = Image.open(image_path)
if image.mode != "RGB":
image = image.convert("RGB")
image = image.resize((int(image.size[0] / factor), int(image.size[1] / factor)))
pixels = image.load()
output_filename = os.path.splitext(filename)[0]
max_retries = 5
retry_delay = 1
success = False
for attempt in range(max_retries):
try:
with open(f"{os.path.join('/tmp/output', output_filename)}.lua", 'w') as f:
bits = []
for y in range(image.size[1]):
for x in range(image.size[0]):
p = pixels[x, y]
p = ("{:03d}".format(p[0]), "{:03d}".format(p[1]), "{:03d}".format(p[2]))
bits.append(''.join(map(str, p)))
f.write("require(script.Parent.Parent):Draw(" + str(rate) +
", Vector3.new(0,0,0), {" + str(image.size[0]) + "," + str(image.size[1]) +
"}, '" + ''.join(bits) + "')")
print(f"Processed: {filename}")
success = True
break
except FileNotFoundError as e:
print(f"Error opening file for {filename}: {e}")
if attempt < max_retries - 1:
print(f"Retrying in {retry_delay} seconds...")
time.sleep(retry_delay)
else:
print(f"Failed to process {filename} after {max_retries} attempts.")
if success:
print("All files processed successfully!")
else:
print("Some files could not be processed after multiple attempts.")