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 HEIF and AVIF images.
  • Encoding of 8, 10, 12 bit HEIF and AVIF images.
  • EXIF, XMP, IPTC read & write support.
  • Support of multiple images in one file, e.g HEICs and AVIFs files and PrimaryImage attribute.
  • HEIF native thumbnails support.
  • Adding all this features to Pillow in one line of code as a plugin.

Install

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.heif", 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 AVIF files as the same as with HEIF files. Just use separate function to register it:

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

Uploaded Source

Built Distributions

pillow_heif-0.6.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.2 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pillow_heif-0.6.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (780.3 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.6.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.6.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.6.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.2 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pillow_heif-0.6.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (780.6 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.6.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.6.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.6.0-cp38-abi3-manylinux_2_31_armv7l.whl (8.0 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.31+ ARMv7l

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

Uploaded CPython 3.8+ macOS 12.0+ ARM64

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

Uploaded CPython 3.7+ Windows x86-64

pillow_heif-0.6.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.6.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.6.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.6.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.6.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.6.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (946.7 kB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ i686

pillow_heif-0.6.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.6.0.tar.gz.

File metadata

  • Download URL: pillow_heif-0.6.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.6.0.tar.gz
Algorithm Hash digest
SHA256 cdb57410104e2416a356793ad0cdc05e70aac42772a311fc439e857837ec4ea3
MD5 ffda6d8eec34f32c4260813ee47329f4
BLAKE2b-256 0924a090f7a252b80e86842212ebd2cdb1b78b2c921f17704ba7f5354baa420c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4dacf9f07a78a7b9f70837d452dae06ce2625fea2a92c345c02136eaf7da5a54
MD5 754f656351cd4bce3deb6ac95da62cfc
BLAKE2b-256 196b08779a995b04597eb136a21bab13f0f3dd6fd91b0aae251c44a212ffd0f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 87f8289806847d685177d1f3b860c7772e7606662221acc9761f47cf13486a07
MD5 44aed9ff3ef97c7cf0529a1abbee118e
BLAKE2b-256 60a1699c6310bb499c2dda2396f1271348dbdb49d1977b218b471bf44975e18d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 625b5cb37b85376ae53d6b3eac3e387603562076deda1f98f18cf60dda45a1f5
MD5 a5f9819140585ed5b441de1725164b2d
BLAKE2b-256 f56dbfac264a95c51094e6aceac5c6f5780149e71e428195212e1b96d09fce38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a6fc07687f5f2473c5fc2f4ec6509dd13b6bbe6704daae33dde1e64aa45c5c3b
MD5 cc030093faf515c8f33b6d13c30ca1d6
BLAKE2b-256 ea99bc2199fd3a854c511e601f585e8ee9ce8334855141d3677ebf1dc3902497

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 395f5096ff4f60cb65876b96d32880f6fa91f83541017b410da23c2566d4298c
MD5 217c13480d74047910561b8a0bbb28fb
BLAKE2b-256 10570d4085127b1b82b60a70d95ebbc075851a2d04621dcdc367d367805652ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 a1696c8375f944e553893c40c62270f7729ad8d8e9eaa2eeceb92671e33a2164
MD5 a6128809505108285dd6a5a29bec8b02
BLAKE2b-256 91280624d023cce9eb72973874c22dc5d370945eb3df2edb0393df6cf66fff95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 13369b6fdf1582b357d7e526b57fffb542e05a5f6e830dd57eb7b6f7c39d1e47
MD5 bbdc51f9be89913c0ac5f43b4e36bd52
BLAKE2b-256 c7f29858a77c5534a3741590da3f7afc5493fde2606548ed8ac2c0ddaa890761

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5c708ee1aa3ca606fe7176ce85ec47fad88a2cf920eb1d259ebc8e45588b8751
MD5 e8cf058320d1bfd1191b964dd7c68cf9
BLAKE2b-256 05ff61765df3393d60d31a7126925f323bfa6e288ff877289c87ac88ca572837

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp38-abi3-manylinux_2_31_armv7l.whl
Algorithm Hash digest
SHA256 0aa32f79f07ae0fa28b77e43f81adf2d1c04066bf37bfb640d01264876cde58b
MD5 f91ca17059f423dd9a4e2cf68eaeab3d
BLAKE2b-256 027f544d0f18dcfc9c3998d207b035dee14cb0f98ce3d7edaa6538fdb5d25ba9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp38-abi3-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 064226a91dcdb9cd3764aae694a30d1076ac47b6a5ee7b257e9bd8e5ea0405c6
MD5 f44674a1e2ed4ce4a9fb84bbb9ec9d33
BLAKE2b-256 10e56b6f4327b6285cd3a40bd24bc37ff628f52ca6d782d6df83bb72f5d2fb60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5ee44ac1edb38366a534abd1aac1e2fddf3c4613605a8f127c57c41efb55f859
MD5 802da0a48f25a605e954e81a66758e0a
BLAKE2b-256 5c5fac74808ec0418b343907f367cfc5f15b6d10bb61cf4f473cc5cb7c554e9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 523335385f631f008e84a841713e7923133ba1d3d30c0c275ef8a772e65e3ae8
MD5 86a799a3bc5f9ff43916890027a4eb92
BLAKE2b-256 9ddd0c8b9c2eebb558562f4886655c4fdd4e22a76300df27b0146a5aff281789

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3155475ddea3e396f964a1e5afed9335a657465748dfbf066a23b64eb5ab4327
MD5 9b6c15f9e182dd187bb7b4da6e4a9b0e
BLAKE2b-256 c3557a43cdb30f5ebd63ff5c28746ff1891085c3220ed779175b32ef1c56825d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp36-abi3-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 a4eb7a8ef8fbdd5b87114311c229bcd4005628879e0ecec0c65b1d3179703674
MD5 4d97ff39a35dd5dac81b2151710b3941
BLAKE2b-256 8a35876743280fa175905896c8bf59ea27e5f238c5830e77b215b1edf4ceaf3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 73f89585a7881b5e046182b3cb99fb7cac8e6ef69553f4a56c4fdec55505aea4
MD5 fd723f44c26b2beb07b1785c48dd6005
BLAKE2b-256 846165b917a15a2867082ae39a74fac2a02ee46d25a0cea806d83567c3897650

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 900320adb0dfd21a80f1188c16d2f0870232353fa4b84f8b882994dcd7245c81
MD5 d80286258222355108948cab959d7642
BLAKE2b-256 5ffc4c6693c94601e7188304ff4c0dd7da60bd82ee8fa6dc56d863e11d8d1614

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0e8010fadfcc46d88c715a807c82172836fa1acea8cefba5437810634e30452c
MD5 53d5c4e114caf378ee5c5e0476bc9011
BLAKE2b-256 f6ad965674104b04527b8fd01e5e8c29b19c10e2056a091c402f50018268e531

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.6.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 637533df0d6725d7124df549fd3cae756130eb14a51dcdf0e99142e6857f0e62
MD5 614e56739bea6e03e56041f8d9a06249
BLAKE2b-256 0060d39488151c7ba5c1a46f8e07a6e712828dc9209ab0c537511ae50f72a96f

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