Last active
August 26, 2022 22:21
-
-
Save SaidTorres3/7346082feeb206f9f0c7d8ccd21445f5 to your computer and use it in GitHub Desktop.
HEICToJPEG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import sched | |
import pillow_heif | |
import os | |
from PIL import Image | |
path = "C:\\Users\\JURIDICO 4\\Documents\\Code\\Otros\\hotel\\images" | |
# path = "C:\\Users\\JURIDICO 4\\Documents\\Tasks\\elexpt" | |
def getFilesRecursive(path): | |
files_names = [] | |
for currentpath, folders, files in os.walk(path): | |
for file in files: | |
files_names.append(os.path.join(currentpath, file)) | |
return files_names | |
def transformAllImages(): | |
files_names = getFilesRecursive(path) | |
for file_name in files_names: | |
if file_name.endswith(".HEIC"): | |
heif_file = pillow_heif.read_heif(file_name) | |
image = Image.frombytes( | |
heif_file.mode, | |
heif_file.size, | |
heif_file.data, | |
"raw", | |
) | |
image.save(os.path.join( | |
file_name.replace(".HEIC", ".jpg")), "JPEG") | |
os.remove(file_name) | |
print("Done.") | |
s = sched.scheduler(time.time, time.sleep) | |
def do_something(sc): | |
print("Working...") | |
# do your stuff | |
transformAllImages() | |
sc.enter(60, 1, do_something, (sc,)) | |
s.enter(0, 1, do_something, (s,)) | |
s.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment