This release is a pre-release and may not be stable for production use.
heif-image-plugin
A HEIF/HEIC and AVIF plugin for Pillow based on libheif.
Installation
You can install heif-image-plugin from PyPI:
pip install heif-image-plugin
Bundled libheif and codecs
pip install 'heif-image-plugin[libheif]'
The [libheif] extra installs the libheif-binary package, which provides libheif
and codecs. The plugin uses this package when installed; otherwise, it requires
system libheif.
Ubuntu system libheif
Ubuntu 24.04:
apt-get install --no-install-recommends \
libheif1 \
libheif-plugin-libde265 \
libheif-plugin-x265 \
libheif-plugin-aomenc
Minimal supported libheif version is 1.17.x.
macOS with Homebrew
The macOS wheel expects @rpath/libheif.1.dylib, while Homebrew's libheif uses
an absolute install name. Build the extension against Homebrew's library so it
records the correct path.
With a C compiler and Python development headers available, run the following
from the repository root in a Python environment without libheif-binary:
brew install libheif
pip install 'setuptools>=77.0.3' 'cffi>=1.15.1'
LIBHEIF_PREFIX=$(brew --prefix libheif)
CPPFLAGS="-I${LIBHEIF_PREFIX}/include" LDFLAGS="-L${LIBHEIF_PREFIX}/lib" \
pip install --no-build-isolation .
--no-build-isolation prevents pip from installing libheif-binary
as a build dependency.
How to use
Just import once before opening an image.
from PIL import Image, ImageOps
import HeifImagePlugin
image = Image.open('test.heic')
ImageOps.exif_transpose(image, in_place=True)
# requires libheif with a HEVC or AV1 encoder
image.save('test.avif')
Decoding errors are exposed as HeifImagePlugin.HeifError, with code,
subcode and message fields.
Downsampling defaults to 'best', which selects 'sharp-yuv' for RGB/RGBA images
with 4:2:0 subsampling when supported, and 'average' otherwise.
Encoder-specific parameters can be passed when saving:
image.save(
'test.avif',
quality=90,
subsampling='420',
downsampling='average',
encoder='aom',
concurrency=4,
encoder_params={'speed': 6},
)
To encode AVIF with SVT-AV1, use encoder='svt'. SVT supports only 4:2:0
subsampling; omit subsampling or set it to '420':
image.save('test.avif', encoder='svt', subsampling='420')
How to contribute
Contributions are welcome:
- Clone the repository:
git clone https://github.com/uploadcare/heif-image-plugin.git. - Build the development image:
make docker_build. - Start a development shell:
make docker_shell. - Make your changes and add tests.
- Run
make lintandmake testinside the container. - Commit your changes on a new branch and open a pull request against uploadcare/heif-image-plugin.
Building from source
Building from source requires a C compiler and Python development headers.
On Linux and macOS, a normal pip install . automatically installs libheif
headers and libraries in an isolated build environment. Install runtime libheif
separately, using the [libheif] extra or system packages described above.
To build against system libheif without libheif-binary, install libheif
development headers and its library, plus setuptools and CFFI, then run:
pip install --no-build-isolation .
Changelog
0.9.0
- Reading and saving now use libheif directly. The
pyheifdependency is removed. Theheif-encexecutable andHEIF_ENC_BINsetting are no longer used. - Added the
[libheif]installation extra, which installslibheif-binary. Without this extra, system libheif 1.17 or later is required. - Wheels for CPython 3.9+ are provided for Linux (glibc 2.28+ and musl 1.2+, on x86_64 and ARM64) and macOS 11+ (universal2). Other platforms require a source build, as does using libheif from Homebrew.
- Decoding errors now use
HeifImagePlugin.HeifErrorinstead ofpyheif.error.HeifError. - Changed default chroma downsampling from
averagetobest: usessharp-yuvwhen possible, andaverageotherwise. - Added saving of palette images (
PandPAmodes), including transparency. - Saving now preserves the displayed EXIF orientation across supported libheif versions.
0.8.1
- Added SVT-AV1 support for AVIF encoding with
encoder='svt'(4:2:0 subsampling only)
0.8.0
- Minimal supported Python version is 3.9
- Minimal supported libheif version is 1.17.x
- Added
encoder_paramsparameter for passing custom encoder parameters when saving - Changed the default chroma downsampling algorithm from
nntoaverage - Default chroma subsampling is now explicitly set to 4:2:0
0.7.0
- Depends on pyheif>=0.8.0; dropped support for older versions
0.6.2
- Fix for buggy LA mode in libheif 1.17.0 - 1.18.2
- Fixed unsupported color conversion for some images
0.6.1
- Added compatibility with Pillow 10.1+
0.6.0
- Minimal supported pyheif is 0.7.1
- Added
downsamplingparameter for saving. Works only withsubsampling== 2. - Transformations support updated to the latest libheif and pyheif
0.5.1
- Fixed HEIF saving in '1' mode
0.5.0
- Added HEIF saving support if
heif-encis installed (part of libheif) - Fixed
HeifImageFile.verify()call - Extensions
.heic,.avif,.heif,.hifare handled by the plugin
0.4.0
- Bypass some decoding errors when
ImageFile.LOAD_TRUNCATED_IMAGESis True.
0.3.2
- Depends on latest pyheif.
0.3.1
! This version requires pyheif with pyheif.open API. As of 2021.11.25 this API
isn't released and is in pyheif's master. See install-pyheif-master-pillow-latest
target in the Makefile to install it.
- Fixed potential vulnerability with arbitrary data in exif metadata.
0.3.0
! This version requires pyheif with pyheif.open API. As of 2021.11.25 this API
isn't released and is in pyheif's master. See install-pyheif-master-pillow-latest
target in the Makefile to install it.
pyheif.openAPI is used for lazy images loading.- Fixed an error when the plugin tries to load any ISOBMFF files.
- AVIF files should work before, but now this is official.
- Patched versions of
pyheifandlibheifwith exposed transformations are supported. In this case opened image isn't transformed on loading and orientation is stored in EXIFOrientationtag like for all other image formats. This is faster and consumes less memory.
0.2.0
- No need to register, works after import.
- Fill
info['icc_profile']on loading. - Close and release file pointer after loading.
- Decoding without custom HeifDecoder(ImageFile.PyDecoder).
Acknowledgments
This project started with Christian Bianciotto’s pyheif-pillow-opener.
Metadata
Release files for heif-image-plugin 0.9.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| heif_image_plugin-0.9.0b1.tar.gz | 32.3 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| heif_image_plugin-0.9.0b1-cp39-abi3-musllinux_1_2_x86_64.whl | CPython 3.9 | abi3 | Linux musl 1.2+ x86-64 | Details |
| heif_image_plugin-0.9.0b1-cp39-abi3-musllinux_1_2_aarch64.whl | CPython 3.9 | abi3 | Linux musl 1.2+ ARM64 | Details |
| heif_image_plugin-0.9.0b1-cp39-abi3-manylinux_2_28_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| heif_image_plugin-0.9.0b1-cp39-abi3-manylinux_2_28_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| heif_image_plugin-0.9.0b1-cp39-abi3-macosx_11_0_universal2.whl | CPython 3.9 | abi3 | macOS 11.0+ universal2 (ARM64, x86-64) | Details |
Total release size: 595.3 kB
Release files / heif_image_plugin-0.9.0b1.tar.gz
| Download URL | heif_image_plugin-0.9.0b1.tar.gz |
|---|---|
| Size | 32.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32daddf31d76588e98eb3efa36e9b106e53296f8a9e40374c5f536fad04a73e6
|
|
BLAKE2b-256 checksum How to use checksums |
d0e03c120cc8eb05b39e7b7fd957724a1564a6bb390461e8ebba022c0592ccfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / heif_image_plugin-0.9.0b1-cp39-abi3-musllinux_1_2_x86_64.whl
| Download URL | heif_image_plugin-0.9.0b1-cp39-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 171.1 kB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8362c27d992554810f4899c3275d5868721872e4233f30a1730b240354e8ded3
|
|
BLAKE2b-256 checksum How to use checksums |
1f19aa94fe1dab44e1375a7e310c1b52f49acf43caa73cc16e51b7717cbc5db1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / heif_image_plugin-0.9.0b1-cp39-abi3-musllinux_1_2_aarch64.whl
| Download URL | heif_image_plugin-0.9.0b1-cp39-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 158.4 kB |
| Tags | CPython 3.9 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
0f52517de6a41396095aef4aa69d6a59d42ee1390c566235f1ce71bcf8c3a6d3
|
|
BLAKE2b-256 checksum How to use checksums |
77e76c2661772a4995ebe3e7654a0efb3b5a3149b86e991d91269f06f48eacce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / heif_image_plugin-0.9.0b1-cp39-abi3-manylinux_2_28_x86_64.whl
| Download URL | heif_image_plugin-0.9.0b1-cp39-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 90.7 kB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a0c67f9b5f4c906c080f060b9f47628294d69c114b57068abc5c11c7cd6f11a7
|
|
BLAKE2b-256 checksum How to use checksums |
2cc712ef9d59907d42c211b6e38937e46450b6fcfee5eecbd53451e8cd977f49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / heif_image_plugin-0.9.0b1-cp39-abi3-manylinux_2_28_aarch64.whl
| Download URL | heif_image_plugin-0.9.0b1-cp39-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 90.1 kB |
| Tags | CPython 3.9 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
5ff71593a869305d9b3f4e606318effb7192b7fd977753e4efa66d19c2080b66
|
|
BLAKE2b-256 checksum How to use checksums |
108754aa38fe5dc5f6b88c4933b894288fa49cec3e276b315875dbdd3e86638b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / heif_image_plugin-0.9.0b1-cp39-abi3-macosx_11_0_universal2.whl
| Download URL | heif_image_plugin-0.9.0b1-cp39-abi3-macosx_11_0_universal2.whl |
|---|---|
| Size | 52.6 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
773105b6b28aed9d6679333cfa32f3ad7ccea138677621bc82e3c02343d4945e
|
|
BLAKE2b-256 checksum How to use checksums |
70d952e9ee87f5e72e43ec95bfb8fa3fbe2cbc2e21c9331b88156d8f37c760e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|