PyHEIF is a Python 3.6+ interface to the `libheif` C library, enabling decoding of HEIF (High Efficiency Image Format) and HEIC images. It facilitates converting HEIF/HEIC images to raw pixel data, commonly used with libraries like Pillow. The current version is 0.8.0, with releases typically tied to Python version support and `libheif` updates, as well as new features.
pip install pyheifVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to decode a HEIF/HEIC image using `pyheif` and convert it into a Pillow `Image` object. It also shows how to handle both single-image and multi-image HEIF files introduced in `pyheif` 0.7.0. The decoded image is then saved as a PNG file. Remember to replace 'example.heic' with a path to a valid HEIC file.
Install `libheif` via your system's package manager (e.g., `sudo apt install libheif-dev` on Debian/Ubuntu, `brew install libheif` on macOS, `vcpkg install libheif` on Windows) before installing `pyheif`.
Check the type of the object returned by `pyheif.read()`. If it's a `HeifContainer`, iterate through `heif_container.heif_files` or access `heif_container.primary_image` to get individual `HeifFile` objects before accessing image attributes like `mode` or `data`.
If HEIF encoding is required, consider using other tools or libraries that specifically offer encoding capabilities.
Install `libheif` via your system's package manager. For Debian/Ubuntu: `sudo apt install libheif-dev`. For macOS: `brew install libheif`. For Windows, consider `vcpkg install libheif:x64-windows` or manual installation.
Verify that the input file is a correctly formatted HEIF/HEIC image. Check its integrity and ensure it's not a different image format with a `.heic` extension. Update `libheif` to the latest version if possible.
If `pyheif.read()` returns a `HeifContainer`, you need to access individual `HeifFile` objects within it. Iterate using `for heif_file in heif_container.heif_files:` or get the primary image via `heif_container.primary_image` to access its attributes.