-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (49 loc) · 1.71 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
from PIL import Image
def list_dir(dir):
return os.listdir(dir)
images = input("Enter file names: ").split(" ")
isReadDir = False
activeDirectory = ""
supported_image_files = ['.webp', '.tiff', '.tif', '.git', '.png', '.eps', '.raw', '.cr2', '.jpg', '.net', '.orf', '.sr2', '.jpeg', '.bmp']
def validate_extensions(values: str(list)):
result_array = []
for value in values:
for support_ext in supported_image_files:
if value.endswith(support_ext):
result_array.append(value)
return result_array
if images[0] == "dir":
activeDirectory = images[1]
images = list_dir(images[1])
isReadDir = True
images = validate_extensions(images)
images_converted = images
def generate_path(path_for, use_cwd):
if use_cwd == True:
path_str = ""
path_str += os.getcwd()
path_str += '\\' + path_for
else:
path_str = ".\\" + path_for
return path_str
output_file = generate_path(input("Enter output file name: "), False)
def convert_images(image_list):
loop_count = 0
result = []
for current_image in image_list:
loop_count = loop_count + 1
if isReadDir:
c_image = activeDirectory + "\\" + current_image
# Opening image
opened_image = Image.open(c_image)
# Converted Image
converted_image = opened_image.convert('RGB')
if loop_count == len(image_list):
result = result
converted_image.save(activeDirectory + "\\" + output_file, save_all=True, append_images=result)
else:
result.append(converted_image)
# Converting
convert_images(images_converted)
print("Images converted successfully!")