Skip to main content

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

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

Uploaded Source

Built Distributions

pillow_heif-0.9.3-pp39-pypy39_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.3-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (834.2 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.9.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.5 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pillow_heif-0.9.3-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (6.7 MB view details)

Uploaded PyPy macOS 10.9+ x86-64

pillow_heif-0.9.3-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.3-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (834.2 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.9.3-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.3-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.3-cp38-abi3-macosx_12_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.8+ macOS 12.0+ ARM64

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

Uploaded CPython 3.7+ Windows x86-64

pillow_heif-0.9.3-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.3-cp37-abi3-musllinux_1_1_x86_64.whl (8.0 MB view details)

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

pillow_heif-0.9.3-cp37-abi3-musllinux_1_1_i686.whl (1.5 MB view details)

Uploaded CPython 3.7+ musllinux: musl 1.1+ i686

pillow_heif-0.9.3-cp37-abi3-musllinux_1_1_aarch64.whl (7.1 MB view details)

Uploaded CPython 3.7+ musllinux: musl 1.1+ ARM64

pillow_heif-0.9.3-cp37-abi3-manylinux_2_28_armv7l.whl (670.7 kB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.28+ ARMv7l

pillow_heif-0.9.3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.5 MB view details)

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

pillow_heif-0.9.3-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (985.8 kB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ i686

pillow_heif-0.9.3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.7 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.7+ macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pillow_heif-0.9.3.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.3.tar.gz
Algorithm Hash digest
SHA256 1076c36735cf0ed7216f6bb819af65bb5eed4e866e3debe3f580245e74571b9e
MD5 cfc9ef8683ea6d59bf1c6678054b45e5
BLAKE2b-256 eca154a57a796adea5fd7272e94a4597acdd9fc03779f5efad58e291455784a8

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e20f65c0ceb644e3cb69407ff17767a8c8d430e9a49b92d7fb0e15636d6cde8
MD5 2862f2ff7cc699982cff2e4c3df74aa2
BLAKE2b-256 d4c720fee47262bc474144ef92bf9c5f1c6c74b2407401efa4bf042e66b481b3

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 5352a879684a96ca971047304e6b858741ebcec4fdddaa4a4ec9e558552b1e42
MD5 efdc94200db5101f59922a4366b592f4
BLAKE2b-256 b25129e6cabb458901cba08ee34659a0d040c339ebeb5bcd95f03a4fe02c548c

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 88bd20c0bb2d607a1c9e5776937a1ef1a932050480bd449f95da9594c5b8ebd6
MD5 ae9da7605db688f9f3d9e4e1a78abf9a
BLAKE2b-256 5d632c246014e1de3418e602fe29b50c5b2469b4bb02dd535dbe6470e173e39e

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-pp39-pypy39_pp73-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ea8624ccde807a0972876063475c0b2b2acbe8017df1759b55a460b12f0e346b
MD5 8c9c46c54f84cbcc7a60550ae34ea0b4
BLAKE2b-256 cfe80061ee71659284acbd79af332073c701c197683364ad2ac4c55cac522dd8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.3-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9834a20f16632d32228f6eb39f09d8d3f51e56283c4148f9ba1e728d49867aa5
MD5 fbfd3f5f81592b35b60a1c028b163888
BLAKE2b-256 6235b1704bdf2106ccb4709c50dd8708d92ea8c164dfcae32e1f1f90d88db217

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.3-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4a5890d632550c760f53d3246c72c5734feb359eae276a183c4556cf7f918d9a
MD5 3a02b6dea26d3b18aa6fd999317abe47
BLAKE2b-256 93e18b0dc5310cbf33544e0363754d68e54e0c61d0e362335bf9144cad4fe617

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.3-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 20e35f48ad489290c094813c5ae80cdca9fd6c5b44b9eb7b14bc1db1c8d3a023
MD5 8e38139f18f0dd0e94e246cdce36aea9
BLAKE2b-256 688c69edbf62d379d667cf83ca956a03831444811cea245e97dcc0f4e5f38460

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.3-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7744d10b76447bd9404163557894b85800e53e1a3428086365266519b29ac231
MD5 e57eec6aa641ba0c804bfe0e5012296c
BLAKE2b-256 40115b6d67707f356a32f097bd9612c5e1b47320b0b6b0eac6ad679bce55db17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp38-abi3-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 a7c8be79e7977eae1b81352f2bc63ded2e7965aeda37cc791df4493e5809863a
MD5 0e56cbd2455735378657d009be1c95ee
BLAKE2b-256 336523247169ba44a0579a5e66937ef72fea19ead1ba4bc028717b4c1fe6529e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 424bd1c8627714001df443c61bf7fc93226da8548dc1979f92cd275c8399ea59
MD5 c7c254c59f88b0dd7b68282e1bfb31f4
BLAKE2b-256 9bad128201e17644e6702cf6c8a6e432a417371388da52acf2b2b5077285bcb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 6b05946ea72c53d93fda64092a9716b8bae52319c96bc308a9b9d8b47fbaf21a
MD5 215fe89ca18e0118bbeee25edad420ce
BLAKE2b-256 c7d34e39af540072b4017cf3444402cfdcb20789654cb682836ae4a5958272f9

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-cp37-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 189f31fc23db2d90246003d8342bfe192b6a1c557c96041a4ac873c8fcfb8f1d
MD5 74df8bc9ac5f68401ea1644b0e83a32a
BLAKE2b-256 63763d43ebcb3c3de2f241572d143ce05dcb8a90a8f74f0199b8e61416827997

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-cp37-abi3-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 178f381a843b046489bf6e74cadb1dd6e31f2adbba5775950d29c93c10587d6a
MD5 09ca8a4ab2922d51dbf4a440ad1bc34f
BLAKE2b-256 9726a45cf9b5b9f209d2b53a8bacba83fdd1c032994d1b587eda800fd6bddd3e

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-cp37-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 e64d0489cb16ff5ac2af2c9126db44ac5e285b4ab3e2f23396a5301f726eba4f
MD5 358fde16c39670240cf08ce8df2dee55
BLAKE2b-256 3f212f4f090cf0ad53b67e765afa37d5cac754a7455f72b085da0e903d2c716f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 8e177f866a390cb3c71d6614a36bcc8d7c3691ac300506b804df966e7c1d409d
MD5 6abed357215d28ad446911c2368d1249
BLAKE2b-256 ac98e5e91971f07f4c2a6c3f5649dc9db376ea2e45509ab6604799dac3d21b9a

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4ed3abb13ddc90ae3ba0670c8d0d062b9b0340c223ab13cafcfda3019a59230
MD5 2fe3ce1cd83ec260c0b590ccfddee02a
BLAKE2b-256 13ba4702b2394a8bb341bb4c4ef7159908032d2b89c760b40377b938a82fb51f

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 98fe5ece5a193d768fef4de81a9b0368ed6a5da7e19709966b6f26132da79bde
MD5 41f7d5dd3c37d40ba22fa2cbfd65ab15
BLAKE2b-256 e2dad7f2c456bb7efa7f9095a7f0f536c3347df02a2d2136b5af0c3a78f99154

See more details on using hashes here.

File details

Details for the file pillow_heif-0.9.3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ed605676119d356982294824a6b37b7273f52c86ea2511835090740ccc3abf50
MD5 07047a4c37104fb25bd7b6ba93d2f83c
BLAKE2b-256 e64cc60321cd11fabdc20cce6a948fa136313104b8fd6c640809a2104c536696

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.9.3-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 67156d333568b7fe4ff3bd4ec2abbaedb206457bc1855bc77dc1178c4acf81a9
MD5 a3d8352815b4467f041f3a14f7004773
BLAKE2b-256 79073e6f9416beec628423a0cd94b343c5691b8f18a4ffb59b2a9db259c75bd6

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