Skip to content

Instantly share code, notes, and snippets.

@urigoren
Created November 10, 2023 15:45
Show Gist options
  • Save urigoren/b8dc1c944d313444a4ba1efc953db003 to your computer and use it in GitHub Desktop.
Save urigoren/b8dc1c944d313444a4ba1efc953db003 to your computer and use it in GitHub Desktop.
A python script to convert all HEIC photos in a folder to JPG format
from PIL import Image
from pathlib import Path
from pillow_heif import register_heif_opener
from tqdm import tqdm
from argparse import ArgumentParser
register_heif_opener()
def main(params):
print("Converting HEIC files to JPG")
files = list(Path(".").glob("*.heic")) + list(Path(".").glob("*.HEIC"))
if len(files) == 0:
print("No HEIC files found")
return
for f in tqdm(files):
image = Image.open(str(f))
image.convert('RGB').save(str(f.with_suffix('.jpg')))
if params.delete:
f.unlink()
if __name__ == "__main__":
parser = ArgumentParser()
# delete option, default false
parser.add_argument("-d", "--delete", action="store_true", help="Delete the file after conversion")
params = parser.parse_args()
main(params)
tqdm==4.66.1
Pillow==10.1.0
pillow-heif==0.13.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment