Skip to main content

Python 3.6+ interface to libheif library

Project description

pillow-heif

Analysis & Coverage Nightly build Wheels test docs codecov

PythonVersion impl pypi Downloads Downloads

Mac OS Windows Linux Alpine Linux Raspberry Pi

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.

Note: Here is a light version pi-heif of this project without encoding capabilities.

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 ARMv7(armv7l) wheels are present for Debian 10+(Ubuntu 20.04+) and Alpine 14+. They 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.9.0.tar.gz (8.0 MB view details)

Uploaded Source

Built Distributions

pillow_heif-0.9.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.9.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (834.6 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.9.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.5 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pillow_heif-0.9.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (6.7 MB view details)

Uploaded PyPy macOS 10.9+ x86-64

pillow_heif-0.9.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.9.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (835.1 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.9.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.5 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pillow_heif-0.9.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (6.7 MB view details)

Uploaded PyPy macOS 10.9+ x86-64

pillow_heif-0.9.0-cp38-abi3-macosx_12_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.8+ macOS 12.0+ ARM64

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

Uploaded CPython 3.7+ Windows x86-64

pillow_heif-0.9.0-cp37-abi3-musllinux_1_2_armv7l.whl (1.2 MB view details)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARMv7l

pillow_heif-0.9.0-cp37-abi3-manylinux_2_28_armv7l.whl (673.4 kB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.28+ ARMv7l

pillow_heif-0.9.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.9.0-cp36-abi3-musllinux_1_1_x86_64.whl (8.1 MB view details)

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

pillow_heif-0.9.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.9.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.9.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.5 MB view details)

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

pillow_heif-0.9.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (988.6 kB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ i686

pillow_heif-0.9.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.7 MB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pillow_heif-0.9.0.tar.gz
Algorithm Hash digest
SHA256 9ec32744729a27883fcdc436093995b4805482eb77b0fcf5c91ef6fa1f5f3fdd
MD5 876176241e0ac3c1228f9037c90855fd
BLAKE2b-256 ea3da31d74f8472377cc1a0b45834bc5a8daaf98ad20f9bf01a60c0f1eb18bda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7569b39706a8c2715aba6b01a5c69dda607cec79e5a30f03c75c1662d0d6252b
MD5 2740906e6782769028809f59bb9c33ae
BLAKE2b-256 a6ad88208a4a82483baa2cda6cdb4a639dfad98808446ca1f3802831c5103a51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 c72e170dc102e0a6b74a4490c0f2cd8c9b2d0881bab9469540b4bc17569e7f70
MD5 f78415a0ab0e903563d9732e7874d3a7
BLAKE2b-256 8f5eff985e55ae8eb226be2862be3892637f4d94ec23cb01674ca001e90f51de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c856cfc90e1dc3d07c04aeb0a76d611b7c04c1440d37d572aea0e887ab0af63b
MD5 90c18b7952034d111d4afaf6f1abf160
BLAKE2b-256 8b84c45b04556e5b3765617ec4d461886d7c9878d99c07a166c65074088f45eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dabe64fdf0f34b6d32de741cfee3ed4d4afffc3a3437aa082771ee67fba78e9e
MD5 e11bede0ba57b92190ad9071030bcc3b
BLAKE2b-256 c1c633f3161815bdca9ad8b7aa34db0446cc072a347dc4b9a3d22ad69ba60891

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 08575e6c2dde463cd4b099995275d72343be0d8cfed939123a7ebfe66f2e70b7
MD5 7429ae3abd0e6645c56b61c9f658a39b
BLAKE2b-256 84a2ac7e87bedd0f176883b0df313be158f35b3eae3d7a73a24f985b96bbd929

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f0e0e124dea5af7dcb4c25e236136cc77fb2489d91776e02c1c81feac8d4c648
MD5 7de49ea297730f6bba4c36decde717b7
BLAKE2b-256 52e28710e24c0c8076975d09b1e51fa112814d5717fd98d33eed0127d753751e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ba6b6aa9cc5d4e6355a919e902db120e1155da47f9354b7a467465ba8b956777
MD5 adca141bddcf4e846d4c6e0cdf2e7295
BLAKE2b-256 9f585cc27e8f5402e55cf74e31cd2f53c6b6af6d6511978970e7130a9c364fe1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d659b06d4534ea5bbd11c27fecbc4209bcc5a646d8df4917ba5bff550641b8d6
MD5 791cd727ea10a2dda69f78dbcf4bb88e
BLAKE2b-256 5bd7562f53f8d4fb2ed36b3ec7ca2e98b714ca666c4803b492ea1d18f5c00c7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp38-abi3-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 185612a088a2a5a7086159b45c02b61494918fa9d7fee8533f97aa3a1440bce6
MD5 29dae9729ff931e0f3c52189953dc44b
BLAKE2b-256 05df62917f074aae42a4d17a00809014c78f7ee9e249efda886cf5a00de38b65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a98c2d9dc7cce25b7a10da900f1d9fb362870d69a250b9f8f4c2f6f00e572c65
MD5 90045c6db5332691f19d53a372a4a0d8
BLAKE2b-256 f0cd4f7c7a1d1aa4ec09934ea13087d25dd853131c8a60d54c36a9e8c3d83bdb

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.0-cp37-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 dab42a6b39d7811b400fe7dda8b3569ad4a3aaa5078ff14625ac5a58836f00f0
MD5 6aab95ce1e59e77deec5ee97904ba59f
BLAKE2b-256 9641d999d9e6c47f585975810ca9207f2d38099c257fa303c27280e758b78dd8

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.0-cp37-abi3-manylinux_2_28_armv7l.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp37-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 a06499453709958c5c34909c451e09defcd0ed21654fd27294769be706222aaa
MD5 06177d7d12320a03cdc8e425902f4bb9
BLAKE2b-256 36dfde778d215423e1087451001ae166756b13538ea71ddbfddfa5eaf320580b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a62c95857b765e5ab99955be721ae76c7b8f426ab5f2c3fa24bc38942716933a
MD5 6d2950da506fff101d0b5db4540fb98a
BLAKE2b-256 837e56a9b4ec4f35aa8edf3e2bffe9e965b354043801a2213996983cb4772888

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a628e491803b7b9e848fe777d3972fd81e93c35b546efe8d50994252561bde64
MD5 a284162c200a7e16d343924e42ab2601
BLAKE2b-256 6c572c36de8cd7b147e2ede06f5e66e2609ac44e5fbeb071cee08e568bdc57e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp36-abi3-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 2063b860302967949a4a7213d8493d4f4b4b6034da660762bf63b7d942dd766a
MD5 73508dd7d5f06fd9f3c8c7b656005326
BLAKE2b-256 810153bd4d576936e3b24bc6abefc2ac3ae001678cf24023b8149518761bce7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 0b9b32efcaf7ccf7ff4c5751f3a9797fb8a658c81b33faa7be71193c772230ab
MD5 8bf5cb6f23ac87b4f5ef6405bd0895c0
BLAKE2b-256 7b8bb3c9eb3ae803597815ceb0164d46e46ee5a72f930a7d26cc137346e2cbde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b19db682cee1ac890371b0e8d89c49e1469ffe636c7f8f3512e4a27c9bd2174b
MD5 2eb2cc86e6d7f52c25b3fc2cb0f9b365
BLAKE2b-256 c88e56aefc2831bfb87f615114f9cb076a29e8059b072aa97ccb2efa126d9cf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4c67432b8514cfc51459184f4a0fc15bdb2abc2f758fb667ebc288195c6789ea
MD5 d0239cec99a9cc3289fef8acfb61dda3
BLAKE2b-256 0e3546397389cde18db16dd6cf146d9d8cc92b154a9d700f676999fec8593996

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1192bc5e8597e6db4249573fdb3d3a8752d6e6d30228276e6e3e9efb5f260f16
MD5 c61f0214d1277ba9875a5028f03cf7b6
BLAKE2b-256 633cd5d8aa1934d5d89c04982b2c5bf676d356d7fe2b55d672fed2bad8db9459

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