forked from ShivamShrirao/diffusers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheictojpg.py
35 lines (33 loc) · 941 Bytes
/
heictojpg.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
# Open the file
import pyheif
from PIL import Image
import piexif
import os
from os import listdir
import sys
# read every file in the directory './data/
# take in argument for directory
if len(sys.argv) > 1:
directory = sys.argv[1]
else:
directory = './data/dog'
for file in listdir(directory):
print(file)
if (file.endswith('.DS_Store')):
os.remove(directory + '/' + file)
elif (file.endswith('.HEIC') or file.endswith('.heic')):
# read the file
heif_file = pyheif.read(directory + '/' + file)
# convert to jpg
image = Image.frombytes(
heif_file.mode,
heif_file.size,
heif_file.data,
"raw",
heif_file.mode,
heif_file.stride,
)
# save the file
image.save(directory + '/' + file + '.jpg', 'jpeg', quality=100)
# remove the original file
os.remove(directory + '/' + file)