9/23/2023

python code to convert heic (Mac image) to jpeg

 refer to code:


.

# pip install pyheif pillow
# brew install libheif



import os
import subprocess

input_folder = "./input/path"
output_folder = "./output/path"

if not os.path.exists(output_folder):
os.makedirs(output_folder)

for filename in os.listdir(input_folder):
if filename.endswith(".heic") or filename.endswith(".HEIC"):
heic_path = os.path.join(input_folder, filename)
jpeg_path = os.path.join(output_folder, os.path.splitext(filename)[0] + ".jpg")

# Run heif-convert to convert the HEIC file to JPEG
subprocess.run(["heif-convert", heic_path, jpeg_path])

print("Conversion complete!")


..


Thank you.



No comments:

Post a Comment