Skip to main content

Python 3.6+ interface to libheif library

Project description

pillow_heif

analysis build published codecov style

PythonVersion impl pypi Downloads

Mac OS Windows Linux Alpine Linux

Library to work with HEIF files and an add-on for Pillow. Using the libheif library via CFFI.

Wheels table:

macOS Intel macOS Silicon Windows 64bit musllinux manylinux
CPython 3.6 N/A N/A N/A
CPython 3.7 N/A
CPython 3.8 N/A
CPython 3.9
CPython 3.10
PyPy 3.7 v7.3 N/A N/A N/A
PyPy 3.8 v7.3 N/A N/A N/A

Note: CPython musllinux/manylinux wheels for i686, x64_86 and aarch64(arm8)

Versions 0.2.X will be last to support Python 3.6

Pull requests are greatly welcome.

Installation

From PyPi:

python3 -m pip install pillow_heif

Or Building from source

Example of use as opener

from PIL import Image
from pillow_heif import register_heif_opener

register_heif_opener()

image = Image.open('image.heic')
image.load()

Example of use as reader

from PIL import Image
import pillow_heif

if not pillow_heif.is_supported('ABC.HEIC'):
  exit(0)
heif_file = pillow_heif.read_heif('ABC.HEIC')
for img in heif_file:       # you still can use it without iteration, like before.
    image = Image.frombytes(
        img.mode,
        img.size,
        img.data,
        'raw',
        img.mode,
        img.stride,
    )

More examples

The HeifImageFile object (as Pillow plugin)

The returned HeifImageFile by Pillow function Image.open has the following additional properties beside regular:

  • info dictionary keys:
    • brand - value from int enum HeifBrand.
    • exif - exif data or None.
    • metadata - is a list of dictionaries with type and data keys, excluding exif. May be empty.
    • color_profile - is a dictionary with type and data keys. May be empty.
    • icc_profile - contains data and present only when file has ICC color profile(prof or rICC).
    • nclx_profile - contains data and present only when file has NCLX color profile.

An UndecodedHeifFile object

The returned UndecodedHeifFile by function open_heif has the following properties:

  • size - the size of the image as a (width, height) tuple of integers.
  • has_alpha - is a boolean indicating the presence of an alpha channel.
  • mode - the image mode, e.g. 'RGB' or 'RGBA'.
  • bit_depth - the number of bits in each component of a pixel.
  • data - the raw decoded file data, as bytes. Contains None until load method is called.
  • stride - the number of bytes in a row of decoded file data. Contains None until load method is called.
  • img_id - id of image, will be needed for encoding operations later.
  • info dictionary with the same content as in HeifImageFile.info plus main - a boolean indicating is this a default picture.
  • thumbnails - list of HeifThumbnail or UndecodedHeifThumbnail classes.
  • top_lvl_images - list of UndecodedHeifFile or HeifFile classes, excluding main image.
  • class supports len and iter:
    • len - returns number of top level images including main.
    • iter - returns a generator to iterate through all images, first image will be main.
  • other useful class methods:
    • thumbnails_all - returns an iterator to access thumbnails for all images in file.

The HeifFile object

HeifFile can be obtained by calling load method of UndecodedHeifFile or by calling read_heif function. HeifFile has all properties of UndecodedHeifFile plus filled data and stride.

Thumbnails

To enable thumbnails, set thumbnails property in options to True:

import pillow_heif

pillow_heif.options().thumbnails = True
pillow_heif.options().thumbnails_autoload = True # if you wish
# or
pillow_heif.register_heif_opener(thumbnails=True, thumbnails_autoload=True)

The UndecodedHeifThumbnail object

  • size - the size of the image as a (width, height) tuple of integers.
  • has_alpha - is a boolean indicating the presence of an alpha channel.
  • mode - the image mode, e.g. 'RGB' or 'RGBA'.
  • bit_depth - the number of bits in each component of a pixel.
  • data - the raw decoded file data, as bytes. Contains None until load method is called.
  • stride - the number of bytes in a row of decoded file data. Contains None until load method is called.
  • img_id - id of thumbnail, will be needed for encoding operations later.

The HeifThumbnail object

You can enable thumbnail autoload by setting thumbnails_autoload property to True.

Also HeifThumbnail can be obtained by calling load method of UndecodedHeifThumbnail, UndecodedHeifFile or HeifImageFile.

HeifThumbnail has all properties of UndecodedHeifThumbnail plus filled data and stride.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pillow_heif-0.1.10.tar.gz (30.6 MB view hashes)

Uploaded Source

Built Distributions

pillow_heif-0.1.10-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.10-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (9.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.1.10-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pillow_heif-0.1.10-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.10-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (9.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.1.10-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pillow_heif-0.1.10-cp310-cp310-win_amd64.whl (5.5 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

pillow_heif-0.1.10-cp310-cp310-musllinux_1_1_x86_64.whl (11.4 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pillow_heif-0.1.10-cp310-cp310-musllinux_1_1_i686.whl (10.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pillow_heif-0.1.10-cp310-cp310-musllinux_1_1_aarch64.whl (10.3 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

pillow_heif-0.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.10-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (9.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

pillow_heif-0.1.10-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pillow_heif-0.1.10-cp310-cp310-macosx_12_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.10 macOS 12.0+ ARM64

pillow_heif-0.1.10-cp310-cp310-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pillow_heif-0.1.10-cp39-cp39-win_amd64.whl (5.5 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

pillow_heif-0.1.10-cp39-cp39-musllinux_1_1_x86_64.whl (11.4 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pillow_heif-0.1.10-cp39-cp39-musllinux_1_1_i686.whl (10.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pillow_heif-0.1.10-cp39-cp39-musllinux_1_1_aarch64.whl (10.3 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

pillow_heif-0.1.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.10-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (9.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

pillow_heif-0.1.10-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pillow_heif-0.1.10-cp39-cp39-macosx_12_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.9 macOS 12.0+ ARM64

pillow_heif-0.1.10-cp39-cp39-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pillow_heif-0.1.10-cp38-cp38-win_amd64.whl (5.5 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

pillow_heif-0.1.10-cp38-cp38-musllinux_1_1_x86_64.whl (11.4 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pillow_heif-0.1.10-cp38-cp38-musllinux_1_1_i686.whl (10.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

pillow_heif-0.1.10-cp38-cp38-musllinux_1_1_aarch64.whl (10.3 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

pillow_heif-0.1.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.10-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (9.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

pillow_heif-0.1.10-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pillow_heif-0.1.10-cp38-cp38-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pillow_heif-0.1.10-cp37-cp37m-win_amd64.whl (5.5 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

pillow_heif-0.1.10-cp37-cp37m-musllinux_1_1_x86_64.whl (11.4 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

pillow_heif-0.1.10-cp37-cp37m-musllinux_1_1_i686.whl (10.2 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

pillow_heif-0.1.10-cp37-cp37m-musllinux_1_1_aarch64.whl (10.3 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ ARM64

pillow_heif-0.1.10-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.10-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (9.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

pillow_heif-0.1.10-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.8 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

pillow_heif-0.1.10-cp37-cp37m-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pillow_heif-0.1.10-cp36-cp36m-musllinux_1_1_x86_64.whl (11.4 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

pillow_heif-0.1.10-cp36-cp36m-musllinux_1_1_i686.whl (10.2 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ i686

pillow_heif-0.1.10-cp36-cp36m-musllinux_1_1_aarch64.whl (10.3 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ ARM64

pillow_heif-0.1.10-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.6 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.10-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (9.6 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686

pillow_heif-0.1.10-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.8 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page