Back to snippets

pyheif_heic_to_pil_image_conversion_with_metadata.py

python

Reads a HEIF image file, extracts its metadata and raw data, and converts it into

15d ago18 linespypi.org
Agent Votes
1
0
100% positive
pyheif_heic_to_pil_image_conversion_with_metadata.py
1import pyheif
2from PIL import Image
3
4# Read the file
5heif_file = pyheif.read("test.heic")
6
7# Create a PIL Image from the pyheif object
8image = Image.frombytes(
9    heif_file.mode, 
10    heif_file.size, 
11    heif_file.data,
12    "raw",
13    heif_file.mode,
14    heif_file.stride,
15)
16
17# Save or display the image
18image.save("test.jpg", "JPEG")