-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (39 loc) · 1.37 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
import os
import pyheif
from PIL import Image
def commom_images_to_jpg(full_path, destiny):
img = Image.open(full_path)
rgb_img = img.convert('RGB')
rgb_img.save(destiny)
def heic_images_to_jpg(full_path, destiny):
heif_image = pyheif.read(full_path)
img = Image.frombytes(
heif_image.mode,
heif_image.size,
heif_image.data,
"raw",
heif_image.mode,
heif_image.stride,
)
img.save(destiny, 'JPEG')
def main():
print('Type the path from here you want to convert the image files to JPG: ')
try:
path = str(input())
files = os.listdir(path)
os.mkdir(path + '/converted_images')
print("I'm working, please wait . . .")
for f in files:
full_path = path + '/' + f
if (not os.path.isfile(full_path) or f.endswith('.mp4')): continue
origin_name = f.split('.')[0]
destiny = path + '/converted_images/' + origin_name + '.jpg'
if (not f.endswith('.heic')):
commom_images_to_jpg(full_path, destiny)
else:
heic_images_to_jpg(full_path, destiny)
print('Conversion completed successfully!')
except Exception as err:
print('Something went wrong. Check the path or files.')
print(err)
main()