-
Notifications
You must be signed in to change notification settings - Fork 2
/
convert.py
52 lines (44 loc) · 1.29 KB
/
convert.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
from tqdm import tqdm
import os
from PIL import Image
from pathlib import Path
num = 1
print("Checking... Do not resize the window!")
x = os.get_terminal_size().columns
y = os.get_terminal_size().lines
current = os.getcwd()
print("Verdict: ", end="")
skip = False
exists = False
p = Path(f"{current}/converted/{x}x{y}") # The path that the frames would go
if p.exists():
exists = True
length = sum(1 for x in p.glob('*') if x.is_file())
if length >= 3284:
print("Already exists")
skip = True
else:
print(f"Expected 3285 files. Got {length}")
print("Too few files in directory")
else:
print("Directory does not exist")
os.system("mkdir converted")
print("Done!")
if skip is False:
if exists is False:
try:
os.chdir("converted")
except Exception as e:
print("Something went wrong trying to enter converted directory")
print(e)
os.mkdir(f"{x}x{y}")
os.chdir(f"{x}x{y}")
else:
os.chdir("converted")
os.chdir(f"{x}x{y}")
for i in tqdm(range(1, 3286)):
image = Image.open(f"{current}/img/{i}.png")
image = image.resize((x, y), Image.Resampling.NEAREST)
image.save(f'new{i}.png')
else:
print("Converted files already exist! Good to go!")