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

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 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.

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

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pillow_heif-0.7.2-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (782.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

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

Uploaded PyPymanylinux: glibc 2.17+ ARM64

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

Uploaded PyPymacOS 10.9+ x86-64

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

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pillow_heif-0.7.2-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (782.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

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

Uploaded PyPymanylinux: glibc 2.17+ ARM64

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

Uploaded PyPymacOS 10.9+ x86-64

pillow_heif-0.7.2-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.2-cp38-abi3-macosx_12_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.8+macOS 12.0+ ARM64

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

Uploaded CPython 3.7+Windows x86-64

pillow_heif-0.7.2-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.2-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.7.2-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.2-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.2-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.7.2-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (952.7 kB view details)

Uploaded CPython 3.6+manylinux: glibc 2.17+ i686

pillow_heif-0.7.2-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.7.2.tar.gz.

File metadata

  • Download URL: pillow_heif-0.7.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a37326c48998511c42d007541a01a38cb4e5f46d4569f2dd52614a7d3726fdcb
MD5 78ef63b7c75ef0a01c5f9ee2cee434f9
BLAKE2b-256 6eca0b08a9415b86fce720e1253f507ccca58ca9b718ff14421aabf9aa2baefe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 557de526d4df837350572b1861da87b134b15719200edacb3a6003bf799f69ca
MD5 b995c9a2434d80a41069d988d945430a
BLAKE2b-256 3a4c66924d878fa8e4a6714628be87d75be49d43f0be6d8cbf54cd2f466ee19a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 caf82157fc9be8bea9ddb4fb1ff2d0d6bc66cb850a0fc627a4acf097d1ad9b42
MD5 214d9541a9f5341e7ab1d841cbd24bae
BLAKE2b-256 1d232ef9dee38f75d0c057d28c724368f55de34d44bf9901aa3e1ba7015d18f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 51aefb21c6d65bad35bf02109c6de30a816ebbd6bfedf4ec7ab546c149d09134
MD5 c77d5882bea413d24c351f73dd7026c6
BLAKE2b-256 f321f37547f49018d54d412d8507a01ea5d0d0693a4b059b4082a1a2bb7a4648

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 05832c17036f4457430ea095d69c2b9b910a4c3f29be879413dd807fd9d3f2a5
MD5 5d9e6dc460438b220c5fbd291592d949
BLAKE2b-256 5d8e3f8da0421a3c8652394027890a6abd189d2ca5b4030a5d70c3f95c650625

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 144cf46ba39574af3ab547beb8fbccb8bd518ffd6cac28c7c656f43875a9c3e2
MD5 36abedd17bfdf24c26448512c76b8add
BLAKE2b-256 710e21cf95af76132c61195a7e556fea2cf3a03cc6a67801b350fd3a419e1ec1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0c6027c2e6916d730f82793ce558ccb925540868b89a4497e16e4ab7bf7d58a8
MD5 971d5c41cff5d158852fff3dd7e2459b
BLAKE2b-256 c2d899624435da1585b4d1b55688e6153c8c0567a64252ba19dd730991f0f54f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0c00d560b61c155fd1a455c324b5890333e4d3d93371e0dc58b2f0b85a88ecf4
MD5 fe73fad6de56f6b2b59297d1c6174faa
BLAKE2b-256 04b0939e22de17091da7b36f20bdbc3c4f9778ee67f7cabfa6b36c930492395f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 11f2146884431cc3a8cb155470999358179dd6eeabdd8aa58e74cf33e65c2991
MD5 03114c14af4d75a36df3e767efab92b4
BLAKE2b-256 b7d18bae39f16ffc1b067af8fbf5b96e3925f0833a1dc1581bc952e3302e7781

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-cp38-abi3-manylinux_2_31_armv7l.whl
Algorithm Hash digest
SHA256 efbc7708c818de8922f526727c804f85840a3a4ab0ca7f6a5ff42bab657691b7
MD5 85cf63d5c7b153449e1a93cdad41cefb
BLAKE2b-256 a3c1b30130243237f53c855c5cca15d779007ea95e1b1c431b0d5d96ca91802c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-cp38-abi3-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 eec11f64946345407319bfc5f3703dfd93cf58565d968737e0857ae4a8ba7147
MD5 929a8bedd89c19f03501f8d0ed074adc
BLAKE2b-256 933793dbb5348953920a377d9f0818f260214044f71ab4249b35ea3fbf9c9fd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pillow_heif-0.7.2-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for pillow_heif-0.7.2-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f1a3cd6deaf58d1df4adbe94fb4b106146985c50f26b5e9fda0a222632391017
MD5 645d03da03cd6cb6e7154166dce2beeb
BLAKE2b-256 16aacbe23a1f6c54941674eac054995ae5039bb53edd6f1de98a57f74ef605f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 092c65ec024a6fd795477a7b28cd8f04bef20b62c3f9f92e3c65031b3fbee7f7
MD5 e650b88fd4621898da5a5c4c2bceb3e3
BLAKE2b-256 0b83ce50306e596edabc406ce9c73cbaed27bc9a7d7ccd42ef234bff17a85d87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1f0d3292f201e674255b367aa92115fe804b9c93fa84fc043578eb939f0b3e34
MD5 36edc66a1dd53a110a0d8a337d55b8b1
BLAKE2b-256 ce5878b30f618c471a0babb69267583f6ef62910dbfd6dac5152f119bf895f97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-cp36-abi3-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 8cc5f8d24ac9e076809e460eca3c292a0f0338a8b4046b6adaf0b5673df9a738
MD5 ef3526ac97a2dab76fff6790b53deb31
BLAKE2b-256 7de3387d60be760662ba28a8912cf8eb74b9768501a10cff1f9e2c0b1e067043

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 f8bfc0c4409a67e8bdd0f0036072132155ed37f8c2a3d7824803b57f3eb91630
MD5 d8c51c33fb29b1de2a4345570f71eb21
BLAKE2b-256 a85d4adf1cc4fdbd617fdcc249913a662b925d3520ca18277aa32a4779a84355

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d825a955fe2a464a0aa8071e7fe64376c21112fadf9db7266c4d7ec7ff3998fe
MD5 a818f314caa55707f7c04a115ec873d8
BLAKE2b-256 c11d7fedb11a66229baf6a1b809554a79d3dea26d2fba79011cb892c490dce03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1281e1211cfdbd65c54c2320ba8dc7c573c4f3921b39bceb804f30607e4a4fd2
MD5 b0ff70537ac28dea6162b17fa27214e8
BLAKE2b-256 fbff0eebee4cf38c1592279944d4ea44cf4262522cb9101faa9d6aaa96d55a7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pillow_heif-0.7.2-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 01dbea3cf8f99bc1f074b05a2bf701ccc70858503f9d8bb017806cfc0c1d2511
MD5 f6ca601cd4578a675a2edc306222e13f
BLAKE2b-256 a1cde0415b49e239e32252fa4fb6bc0b21b5b0cbfceb381c8587bfa856854d88

See more details on using hashes here.

Supported by

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