-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheic-heif-converter.py
More file actions
61 lines (56 loc) · 2.13 KB
/
heic-heif-converter.py
File metadata and controls
61 lines (56 loc) · 2.13 KB
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
from PIL import Image
from pillow_heif import register_heif_opener
from gooey import Gooey, GooeyParser
# Iterate through all the HEIC files in the directory
def convert_images(path):
register_heif_opener()
for root, dirs, files in os.walk(path, topdown=True):
for i,f in enumerate(files, start=1):
#COPY_FROM = Path(root)
input_file = os.path.join(root, f)
print('file:'+input_file)
if input_file.endswith(".heic") or input_file.endswith(".heif"):
try:
with Image.open(input_file) as im:
im = im.convert("RGB")
output_file = os.path.join(root, os.path.splitext(f)[0] + ".JPG")
im.save(output_file, "JPEG")
except:
print(f"Error: {f} is not a valid HEIC or HEIF file")
else:
print(f"Error: {f} is not a valid image file")
def check_slash(string):
slash_to_add = "\\"
if string and len(string) > 3:
return string
else:
newvalue = os.path.join(string,slash_to_add)
return newvalue
@Gooey(program_name='HEIC and HEIF Converter - HEIC/HEIF to JPG.',
menu=[{
'name': 'File',
'items': [{
'type': 'AboutDialog',
'menuTitle': 'About',
'name': 'HEIC and HEIF Converter - HEIC/HEIF to JPG.',
'description': 'Python based HEIC and HEIF Converter - HEIC/HEIF to JPG.',
'version': '1.0',
'copyright': '',
'website': '',
'developer': 'Michael Akridge'}]}])
def parse_args():
parser = GooeyParser(description='HEIC and HEIF Converter')
parser.add_argument('SELECT_PATH', widget='DirChooser',type=check_slash)
return parser.parse_args()
def main():
# setup file path
args = parse_args()
pathvalue = args.SELECT_PATH
print(pathvalue)
convert_images(pathvalue)
print('---- Working ----')
print('-------------------------------------------------')
print('---- Complete ----')
if __name__ == '__main__':
main()