Python interface for libheif library
Project Links
Meta
Author: Alexander Piskun
Requires Python: >=3.9
Classifiers
Development Status
- 5 - Production/Stable
Intended Audience
- Developers
Topic
- Software Development
- Software Development :: Libraries
- Multimedia :: Graphics
- Multimedia :: Graphics :: Graphics Conversion
Programming Language
- Python :: 3
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
License
- OSI Approved :: GNU General Public License v2 (GPLv2)
Operating System
- MacOS :: MacOS X
- POSIX :: Linux
- Microsoft :: Windows
pillow-heif
Python bindings to libheif for working with HEIF images and plugin for Pillow.
Features:
- Decoding of
8
,10
,12
bit HEIC files. - Encoding of
8
,10
,12
bit HEIC files. EXIF
,XMP
,IPTC
read & write support.- Support of multiple images in one file and a
PrimaryImage
attribute. - Adding & removing
thumbnails
. - Reading of
Depth Images
. - (beta) Reading of
Auxiliary Images
by johncf - Adding HEIF support to Pillow in one line of code as a plugin.
Note: Here is a light version pi-heif of this project without encoding capabilities.
Install
python3 -m pip install -U pip
python3 -m pip install pillow-heif
Example of use as a Pillow plugin
from PIL import Image
from pillow_heif import register_heif_opener
register_heif_opener()
im = Image.open("image.heic") # do whatever need with a Pillow image
im = im.rotate(13)
im.save(f"rotated_image.heic", quality=90)
16 bit PNG to 10 bit HEIF using OpenCV
import cv2
import pillow_heif
cv_img = cv2.imread("16bit_with_alpha.png", cv2.IMREAD_UNCHANGED)
heif_file = pillow_heif.from_bytes(
mode="BGRA;16",
size=(cv_img.shape[1], cv_img.shape[0]),
data=bytes(cv_img)
)
heif_file.save("RGBA_10bit.heic", quality=-1)
8/10/12 bit HEIF to 8/16 bit PNG using OpenCV
import numpy as np
import cv2
import pillow_heif
heif_file = pillow_heif.open_heif("image.heic", convert_hdr_to_8bit=False, bgr_mode=True)
np_array = np.asarray(heif_file)
cv2.imwrite("image.png", np_array)
Accessing decoded image data
import pillow_heif
if pillow_heif.is_supported("image.heic"):
heif_file = pillow_heif.open_heif("image.heic", convert_hdr_to_8bit=False)
print("image size:", heif_file.size)
print("image mode:", heif_file.mode)
print("image data length:", len(heif_file.data))
print("image data stride:", heif_file.stride)
Get decoded image data as a Numpy array
import numpy as np
import pillow_heif
if pillow_heif.is_supported("input.heic"):
heif_file = pillow_heif.open_heif("input.heic")
np_array = np.asarray(heif_file)
Accessing Depth Images
from PIL import Image
from pillow_heif import register_heif_opener
import numpy as np
register_heif_opener()
im = Image.open("../tests/images/heif_other/pug.heic")
if im.info["depth_images"]:
depth_im = im.info["depth_images"][0] # Access the first depth image (usually there will be only one).
# Depth images are instances of `class HeifDepthImage(BaseImage)`,
# so work with them as you would with any usual image in pillow_heif.
# Depending on what you need the depth image for, you can convert it to a NumPy array or convert it to a Pillow image.
pil_im = depth_im.to_pillow()
np_im = np.asarray(depth_im)
print(pil_im)
print(pil_im.info["metadata"])
More Information
Wheels
Wheels table | macOS Intel |
macOS Silicon |
Windows |
musllinux* | manylinux* |
---|---|---|---|---|---|
CPython 3.9 | ✅ | ✅ | ✅ | ✅ | ✅ |
CPython 3.10 | ✅ | ✅ | ✅ | ✅ | ✅ |
CPython 3.11 | ✅ | ✅ | ✅ | ✅ | ✅ |
CPython 3.12 | ✅ | ✅ | ✅ | ✅ | ✅ |
CPython 3.13 | ✅ | ✅ | ✅ | ✅ | ✅ |
PyPy 3.10 v7.3 | ✅ | ✅ | ✅ | N/A | ✅ |
PyPy 3.11 v7.3 | ✅ | ✅ | ✅ | N/A | ✅ |
* x86_64, aarch64 wheels.
Sep 30, 2025
1.1.1
Aug 02, 2025
1.1.0
Jun 29, 2025
1.0.0
Mar 15, 2025
0.22.0
Nov 29, 2024
0.21.0
Oct 18, 2024
0.20.0
Jul 27, 2024
0.18.0
Jul 02, 2024
0.17.0
Apr 01, 2024
0.16.0
Feb 03, 2024
0.15.0
Dec 02, 2023
0.14.0
Oct 15, 2023
0.13.1
Aug 09, 2023
0.13.0
Jul 08, 2023
0.12.0
May 10, 2023
0.11.1
Apr 03, 2023
0.10.1
Feb 24, 2023
0.10.0
Jan 22, 2023
0.9.3
Jan 18, 2023
0.9.2
Jan 02, 2023
0.9.1
Dec 15, 2022
0.9.0
Nov 20, 2022
0.8.0
Oct 31, 2022
0.7.2
Oct 28, 2022
0.7.1
Sep 11, 2022
0.7.0
Aug 20, 2022
0.6.1
Aug 05, 2022
0.6.0
Jul 30, 2022
0.5.1
Jul 21, 2022
0.5.0
Jul 04, 2022
0.4.0
Jun 25, 2022
0.3.2
Jun 17, 2022
0.3.1
Jun 11, 2022
0.3.0
May 30, 2022
0.2.5
May 17, 2022
0.2.4
May 02, 2022
0.2.3
Apr 23, 2022
0.2.2
Mar 24, 2022
0.1.11
Mar 17, 2022
0.1.10
Feb 01, 2022
0.1.5
Nov 05, 2021
0.1.4