Skip to main content

heif-image-plugin

Runtime Python coverage Py Versions license

A HEIF/HEIC and AVIF plugin for Pillow based on the pyheif library.

Originally based on the pyheif-pillow-opener code from Christian Bianciotto.

Installation

You can install heif-image-plugin from PyPI:

pip install heif-image-plugin

Install libheif binaries for saving capabilities

Ubuntu 24.04:

apt-get install --no-install-recommends \
    libheif-examples \
    libheif-plugin-libde265 \
    libheif-plugin-x265 \
    libheif-plugin-aomenc

Minimal supported libheif version is 1.17.x.

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 `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},
)

How to contribute

Contributions are welcome:

  1. Clone the repository: git clone https://github.com/uploadcare/heif-image-plugin.git.
  2. Build the development image: make docker_build.
  3. Start a development shell: make docker_shell.
  4. Make your changes and add tests.
  5. Run make lint and make test inside the container.
  6. Commit your changes on a new branch and open a pull request.

Changelog

0.8.0

  • Minimal supported Python version is 3.9
  • Minimal supported libheif version is 1.17.x
  • Added encoder_params parameter for passing custom encoder parameters when saving
  • Changed the default chroma downsampling algorithm from nn to average
  • 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 downsampling parameter for saving. Works only with subsampling == 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-enc is installed (part of libheif)
  • Fixed HeifImageFile.verify() call
  • Extensions .heic, .avif, .heif, .hif are handled by the plugin

0.4.0

  • Bypass some decoding errors when ImageFile.LOAD_TRUNCATED_IMAGES is 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.open API 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 pyheif and libheif with exposed transformations are supported. In this case opened image isn't transformed on loading and orientation is stored in EXIF Orientation tag 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).

Metadata

Release files for heif-image-plugin 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for heif-image-plugin 0.8.0
File Size Uploaded
heif_image_plugin-0.8.0.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for heif-image-plugin 0.8.0
File Interpreter ABI Platform
heif_image_plugin-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.7 kB

Release files / heif_image_plugin-0.8.0.tar.gz

Download URL heif_image_plugin-0.8.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
902a6e7c22cdc5b3c1bc73dcea754c3655332942882a578a004981b9d872230d
BLAKE2b-256 checksum
How to use checksums
23e3dd2604daf990d18fce1bd0b59bb723d8ed83dc9ef0fe70ce11feefb6545e
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.8.0-py3-none-any.whl

Download URL heif_image_plugin-0.8.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec43fd74215e84140f1273bc039a485cee00da6d1ce2f0f6bbff9dccae1a199b
BLAKE2b-256 checksum
How to use checksums
5a79fd2b7230d50bde0e3763344e5c0b73b6a1aa586bbbc188cbd94027c107d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files

0.7.0

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

2 release files

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page