A HEIF/HEIC and AVIF plugin for Pillow based on the pyheif library.
Originally based on the pyheif-pillow-opener code from Christian Bianciotto.
You can install heif-image-plugin from PyPI:
pip install heif-image-plugin
Ubuntu 24.04:
apt-get install --no-install-recommends \
libheif-examples \
libheif-plugin-libde265 \
libheif-plugin-x265 \
libheif-plugin-aomencMinimal supported libheif version is 1.17.x.
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 `heif-enc` binary with installed codecs or plugins
image.save('test.avif')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},
)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.
- 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
- Depends on pyheif>=0.8.0; dropped support for older versions
- Fix for buggy LA mode in libheif 1.17.0 - 1.18.2
- Fixed unsupported color conversion for some images
- Added compatibility with Pillow 10.1+
- Minimal supported pyheif is 0.7.1
- Added
downsamplingparameter for saving. Works only withsubsampling== 2. - Transformations support updated to the latest libheif and pyheif
- Fixed HEIF saving in '1' mode
- Added HEIF saving support if
heif-encis installed (part of libheif) - Fixed
HeifImageFile.verify()call - Extensions
.heic,.avif,.heif,.hifare handled by the plugin
- Bypass some decoding errors when
ImageFile.LOAD_TRUNCATED_IMAGESis True.
- Depends on latest pyheif.
! 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.
! 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.
- 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).