Skip to main content

Python 3.6+ interface to libheif library

Project description

pillow-heif

analysis build wheels test docs codecov

PythonVersion impl pypi Downloads Downloads

Mac OS Windows Linux Alpine Linux

Python bindings to libheif for working with HEIF images and an add-on for Pillow.

Features:

  • Decoding of 8, 10, 12 bit HEIC and AVIF files.
  • Encoding of 8, 10, 12 bit HEIC and AVIF files.
  • EXIF, XMP, IPTC read & write support.
  • Support of multiple images in one file and a PrimaryImage attribute.
  • HEIF thumbnails support.
  • Adding all this features to Pillow in one line of code as a plugin.

Install

python3 -m pip install -U pip
python3 -m pip install pillow-heif

Example of use as a Pillow plugin

from PIL import Image
from pillow_heif import register_heif_opener

register_heif_opener()

im = Image.open("images/input.heic")  # do whatever need with a Pillow image
im = im.rotate(13)
im.save(f"rotated_image.heic", quality=90)

16 bit PNG to 10 bit HEIF using OpenCV

import cv2
import pillow_heif

cv_img = cv2.imread("images/jpeg_gif_png/RGBA_16.png", cv2.IMREAD_UNCHANGED)
heif_file = pillow_heif.from_bytes(
    mode="BGRA;16",
    size=(cv_img.shape[1], cv_img.shape[0]),
    data=bytes(cv_img)
)
heif_file.save("RGBA_10bit.heic", quality=-1)

8/10/12 bit HEIF to 16 bit PNG using OpenCV

import numpy as np
import cv2
import pillow_heif

heif_file = pillow_heif.open_heif("images/rgb12.heif", convert_hdr_to_8bit=False)
heif_file.convert_to("BGRA;16" if heif_file.has_alpha else "BGR;16")
np_array = np.asarray(heif_file)
cv2.imwrite("rgb16.png", np_array)

Accessing decoded image data

import pillow_heif

if pillow_heif.is_supported("images/rgb10.heif"):
    heif_file = pillow_heif.open_heif("images/rgb10.heif", convert_hdr_to_8bit=False)
    print("image mode:", heif_file.mode)
    print("image data length:", len(heif_file.data))
    print("image data stride:", heif_file.stride)
    heif_file.convert_to("RGB;16")  # convert 10 bit image to RGB 16 bit.
    print("image mode:", heif_file.mode)

Get decoded image data as a Numpy array

import numpy as np
import pillow_heif

if pillow_heif.is_supported("input.heic"):
    heif_file = pillow_heif.open_heif("input.heic")
    np_array = np.asarray(heif_file)

Adding & Removing thumbnails

import pillow_heif

if pillow_heif.is_supported("input.heic"):
    heif_file = pillow_heif.open_heif("input.heic")
    pillow_heif.add_thumbnails(heif_file, [768, 512, 256])  # add three new thumbnail boxes.
    heif_file.save("output_with_thumbnails.heic")
    heif_file.thumbnails.clear()               # clear list with thumbnails.
    heif_file.save("output_without_thumbnails.heic")

(Pillow)Adding & Removing thumbnails

from PIL import Image
import pillow_heif

pillow_heif.register_heif_opener()

im = Image.open("input.heic")
pillow_heif.add_thumbnails(im, [768, 512, 256])  # add three new thumbnail boxes.
im.save("output_with_thumbnails.heic")
im.info["thumbnails"].clear()               # clear list with thumbnails.
im.save("output_without_thumbnails.heic")

Using thumbnails when they are present in a file

import pillow_heif

if pillow_heif.is_supported("input.heic"):
    heif_file = pillow_heif.open_heif("input.heic")
    for img in heif_file:
        img = pillow_heif.thumbnail(img)
        print(img)  # This will be a thumbnail or if thumbnail is not avalaible then an original.

(Pillow)Using thumbnails when they are present in a file

from PIL import Image, ImageSequence
import pillow_heif

pillow_heif.register_heif_opener()

pil_img = Image.open("input.heic")
for img in ImageSequence.Iterator(pil_img):
    img = pillow_heif.thumbnail(img)
    print(img)  # This will be a thumbnail or if thumbnail is not avalaible then an original.

AVIF support

Working with the AVIF files as the same as with the HEIC files. Just use a separate function to register plugin:

import pillow_heif

pillow_heif.register_avif_opener()

More Information

Wheels

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
CPython 3.9
CPython 3.10
CPython 3.11
PyPy 3.7 v7.3 N/A N/A N/A
PyPy 3.8 v7.3 N/A N/A N/A

* i686, x86_64, aarch64 wheels.

For armv7l there is a pillow_heif-x.x.x-cp38-abi3-manylinux_2_31_armv7l.whl wheel on pypi for Debian11+ systems. It supports only decoding and builds without x265 encoder.

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.7.0.tar.gz (8.0 MB view details)

Uploaded Source

Built Distributions

pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.3 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (781.1 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.4 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pillow_heif-0.7.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (6.6 MB view details)

Uploaded PyPy macOS 10.9+ x86-64

pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.3 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (781.5 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.4 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pillow_heif-0.7.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (6.6 MB view details)

Uploaded PyPy macOS 10.9+ x86-64

pillow_heif-0.7.0-cp38-abi3-manylinux_2_31_armv7l.whl (8.1 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.31+ ARMv7l

pillow_heif-0.7.0-cp38-abi3-macosx_12_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.8+ macOS 12.0+ ARM64

pillow_heif-0.7.0-cp37-abi3-win_amd64.whl (7.8 MB view details)

Uploaded CPython 3.7+ Windows x86-64

pillow_heif-0.7.0-cp37-abi3-macosx_10_9_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.7+ macOS 10.9+ x86-64

pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_x86_64.whl (8.0 MB view details)

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

pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_i686.whl (1.5 MB view details)

Uploaded CPython 3.6+ musllinux: musl 1.1+ i686

pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_aarch64.whl (7.1 MB view details)

Uploaded CPython 3.6+ musllinux: musl 1.1+ ARM64

pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

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

pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (947.4 kB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ i686

pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.6 MB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ ARM64

File details

Details for the file pillow_heif-0.7.0.tar.gz.

File metadata

  • Download URL: pillow_heif-0.7.0.tar.gz
  • Upload date:
  • Size: 8.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for pillow_heif-0.7.0.tar.gz
Algorithm Hash digest
SHA256 26261582b1437a132f58e17dbf6fd5301689fb2f9f205d119cd32b875f0e0700
MD5 305e51d8075f64ae1d85ad47a4ef267e
BLAKE2b-256 d11d7dc70acf85b19d7f319bb96af4becdc9e6443cce204e27ff41737c095582

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2a908ec284d6bf42a4445b261c1dd65393eb0ed7b1fa1fffc7f69026c4c1e921
MD5 ab98474f5b2a291e0cfc4ee8865e55c2
BLAKE2b-256 c3d07d6641fad1e618e57a7b13eb4712be994492027816128eb19d2ae2a739bf

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 5799ae53b34ec78035ed5955ae90987dbf2ab9bba8aff0e42c654b3d5745aa36
MD5 5f7186fca2e43dafc02bfd2cf34a674b
BLAKE2b-256 c75bb5821968e9813b98cd7a030888c6f00975b69e7adc5695172aaf79fc49d5

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c81b0c04df26feff0cb32948d05161fcb90f236766b3dd4bdf00f9c29e193627
MD5 7932f188c88f7bec1ed55940c5337992
BLAKE2b-256 eb490a81bec4920a3acf561fbc1af2f103f7165773ee3ca4dd4c5de2286005dc

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 31bbaf4129de58a2dec2ac2b62d24fb66ff56fab1d762b00d512e1421886cc42
MD5 0710deffed0c2c4db1c109cdbcd0a5c8
BLAKE2b-256 8dbaa1a5ad3386140b7a16bf7451556e166bb6a1ffd06995577173518348367e

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d0684fd3908a96a9c17c0f11dbff7bdc936a54b12142028b071685f5efc0a3ec
MD5 9f1d63b10fcbe0171983409089ad913c
BLAKE2b-256 d7fca209895c40a7002688c411725f7c22de312a5a55c01c0cf1cdca10ab0526

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 a4a3acd9256c36f6a1899da922b2069227e8e8f20d89ce580b2ff0111516c721
MD5 3a4c6fe98ecc13b2b54669f66933c547
BLAKE2b-256 7d3f8a9781d1d0a8ca8a104ee1b8fca871fcc37113e90530580cdb45f73ba706

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a1bdb98daf42470fb3b9c02b84a618170c872aa58cf013f1ba8dcc2c077f0df6
MD5 4c05024a7433e667a480c5e8a57ae86a
BLAKE2b-256 0b13e2ead4c1c6e8c9e2f961ae0b076a6dea2e09d3c840060c9d885e3f5f904e

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f294c30fc55688c7fc025bfc305e21e059bc43108a877f46045f84e0f07a3eb7
MD5 dd7cb03313c20e622a94e0b8b885e26a
BLAKE2b-256 82a2ebef55c99c32b9e5081aa2d9ec170a8a5d21bc4a11e3c10893f21c2adec3

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp38-abi3-manylinux_2_31_armv7l.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp38-abi3-manylinux_2_31_armv7l.whl
Algorithm Hash digest
SHA256 043f36f5b672e2962bb2181279d6da89aed870deb23a0a22eb7160bf0ef60d91
MD5 5e96476f2ab5d53f9ab8af5b7231f998
BLAKE2b-256 5d086e550d7af6711836237c6b098e2ab3a7ce2ad20d4e85404ec40f4b4cf57b

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp38-abi3-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp38-abi3-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 205b11e41fb09312d584fd25b3691337c86da958824eba4c5a3bb7867dca6f03
MD5 e4432e1f0d9e817ea0d9be7bf5c2fe9d
BLAKE2b-256 4798fdba755e73401df9f9be27be948670a4b858d8490afc2053a1343ce95235

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0d5820d77c5a8445a3e9963982fea22705c555eceea3f237d5e4063b78a3c22f
MD5 883900c36fac953884a64bac11541ea6
BLAKE2b-256 aaec451117051bd36d7dce0a49b4c20ce72984b4e6e7040fd5513127315f3e1d

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp37-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a7d261a33d3ea996c4ce573f8cb52b68d6b9824badfcfc7a306ecd22a7c31c59
MD5 1881f2a32ac06aea14f13aec0d415b63
BLAKE2b-256 293e0e404d776d231a187306efc88767af74026b447417a484a47f8a191dd3ab

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 9b81f2b66188aaab4c02f5a6e52a136e03c6a8cf39491a7d9b94317f29457c6d
MD5 902bfa3d14ab8c47f27e14a46d39c0a4
BLAKE2b-256 6c437c5734cb186484f93138dc380d2fa95d5320f621004b8df97210eb2026e9

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e26f032b934925df2a2bc275e19abb5737fbbba85f686dd6ac553011cd2b7e89
MD5 f66eb225a504088c9901af3185200542
BLAKE2b-256 357b3568dd3e5ade8c5ded9f270cbb972190384aab7fbdf6486994b60616111c

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 ab717840e8d4bb4b2730aec99f28c6039a05b9f0629bf481e4c7d9effd2fb37f
MD5 4ab99148e6368f684c34f58afe571346
BLAKE2b-256 f4bce4675c062578d39f1c1d043ba99f854132a88a1befe32af007dd8c4f5e36

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 895e7b6c32eab5a60352f5da8613be3b44f5ccef0fafaafbb63a6fd461a79c8b
MD5 9649f592cdc3a8ef4f5a68390ef8137d
BLAKE2b-256 79fb169880248dc3b19b1d86d66f396498d73a05536537b8c7ba7e9387d099d9

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 eb79c49992c98b6bd059fd8f3440fb1ebc3b6b222f95c5e34f0e1c1cfd2c0248
MD5 408ea518f97a36318f32eede91476097
BLAKE2b-256 8c45aa8fb832aa86fb3229b5c7f2f782e67dccbdf7e7a004584924637cabaf8e

See more details on using hashes here.

File details

Details for the file pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 80347012d874d0e0712b5fc3235bc9b914e8fb52f781b10d9389c2c8a691b41a
MD5 0099dececa5b8cfb5fe223b12910850f
BLAKE2b-256 d5f2cef9a94de6bf016ceb4809f0c8b9022f9d50f2cecf89d349e3bb1ae76215

See more details on using hashes here.

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