Photos taken with iPhone Live Photo are saved as HEIC files. Compared to JPEG and PNG, this file has less software and is difficult to handle. Therefore, make a note of how to convert the HEIC file to a PNG file.
You can run it from your browser using Google Colaboratory.
Place conv.py in the same hierarchy as the file you want to convert and execute it.
conv.py
from PIL import Image
import pyheif
def conv(image_path):
new_name = image_path.replace('heic', 'png')
heif_file = pyheif.read(image_path)
data = Image.frombytes(
heif_file.mode,
heif_file.size,
heif_file.data,
"raw",
heif_file.mode,
heif_file.stride,
)
data.save(new_name, "PNG")
import glob
lst = glob.glob("*.heic")
for l in lst:
conv(l)
Install with the pip command.
pip install pyheif Pillow
$ python conv.py
$ ls
IMG_3488.heic* IMG_3494.heic* IMG_3497.heic* IMG_3499.heic* IMG_3503.heic* IMG_3510.heic* IMG_3514.heic* a.py*
IMG_3488.mov* IMG_3494.mov* IMG_3497.mov* IMG_3499.mov* IMG_3503.mov* IMG_3510.mov* IMG_3514.mov* env/
Convert HEIC file in specified directory to JPEG with Python --Qiita
Recommended Posts