Python 3.6+ interface to libheif library
Project description
pillow-heif
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.
Project details
Release history Release notifications | RSS feed
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.1.tar.gz
(8.1 MB
view hashes)
Built Distributions
Close
Hashes for pillow_heif-0.6.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fb48d91f22b87ead73db604e064d2eba6f5a1f8612110e1e0828b9332f2345e |
|
MD5 | 07f1fe710e7661bd79825e0e4b82a5d5 |
|
BLAKE2b-256 | e52ffb3bc46e9068d14c3672628fd1681ce91537f6e9c7ef22c2a656b34fbfae |
Close
Hashes for pillow_heif-0.6.1-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fec9a8bcbffd76fdac191841a6f7602868d8bbfff44dc3e38dc6f5e8ed9c1c1d |
|
MD5 | 2e78ec890105229a7f534a5d4c4021f0 |
|
BLAKE2b-256 | e5fc86a72f34dce07bf6073120257d10b4ef61a4510dafa54a63c87c66257639 |
Close
Hashes for pillow_heif-0.6.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd218882e25c61403d55b364f78be254ef99b60c782837f61df2b354f8e6b61f |
|
MD5 | e448d1911b14aebe64fdeebd7edbf00f |
|
BLAKE2b-256 | 6f62d5dd737e086b5cb2ae1fc9655bfcb1d58f88705c1ea73d924b0341aca306 |
Close
Hashes for pillow_heif-0.6.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ec9a6f7f70cff278dd928f4f15f9c226eacde0d45e9d7740bd3fcc09561ad97 |
|
MD5 | d34f5a909c77aded4921462af46a49ab |
|
BLAKE2b-256 | 35a84ca212c7a113926ab87cda70a7df390ef959a80d4dd3361d4ad13bf90275 |
Close
Hashes for pillow_heif-0.6.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe1dffd0c55d837040eee63cf4f592bed80837ddfa255c1ad8e91e2a125e60b0 |
|
MD5 | 0c3fdce9cebd59c68c3d6e0ac92d1b84 |
|
BLAKE2b-256 | c4cc25f09bc348496c9c077854b7b8bfd277c8493f926591701c03ae32e5af83 |
Close
Hashes for pillow_heif-0.6.1-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1aafdf6c40b47e799e85aaba75ed56646702efe3231d8b2118fad6988e5f887 |
|
MD5 | 9a19641cbeaab3b488a254ecbdecb56e |
|
BLAKE2b-256 | ea38460ff2a5f8d9e52be22caca814f4b9b4cf86c09dabbfa4f8b486093a7bac |
Close
Hashes for pillow_heif-0.6.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0e644805eaa0f415e3cedf01b6b490dbfdbab2d7c791278a8cbade35adae564 |
|
MD5 | 9a083b224871f7963724e88b48a48e13 |
|
BLAKE2b-256 | 15db8571e08c931f6d6dedcca43a183a371aee2bc8b7ce57413c4b091205376d |
Close
Hashes for pillow_heif-0.6.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4d144c1b122c63bbb6d9a5ebfb3afff596438195aee7f74fb3957cdb1947591 |
|
MD5 | 90f7911e7202d8728ab47709ecf967f6 |
|
BLAKE2b-256 | 2832a15281d7fa354a35c244fa5e900962d5b312498820e18a1bdd9531e44f19 |
Close
Hashes for pillow_heif-0.6.1-cp38-abi3-manylinux_2_31_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f259e4a4b66ff1cf4798ace5fddd88ec1981034cfdfcb6fd764cfd4a52aea36 |
|
MD5 | b612f0ea8e5b6ca106f80b2c8ba6ce72 |
|
BLAKE2b-256 | ba1efbe01575d69a8abf910a13aca70c998cbe6f95b79fd0f7d51c3ae63dc1f9 |
Close
Hashes for pillow_heif-0.6.1-cp38-abi3-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4445aaa36762b662ec5c4e30967b5a91565fe2fb859c07a935e2162daf38054 |
|
MD5 | bd02dba79d7fd858bf35024bc43faa06 |
|
BLAKE2b-256 | 3687b8650c75ed2cb013da3cd26d978489ec94307dd6bbab7a5334c0d8c22f0e |
Close
Hashes for pillow_heif-0.6.1-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb095fc277fcca92eaecd3786023398cec31e13379f5db38b0a094b018fdab9a |
|
MD5 | 5965475cb00acf70e1b5d7c98173f8fc |
|
BLAKE2b-256 | b904ee996a1d63f0d787efe128b0e049a5e40fb75dd4b5e9482d6cb564b7423c |
Close
Hashes for pillow_heif-0.6.1-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7752f723b982cced911036402e907b4ee1f0254b704682e801340b00f41a412c |
|
MD5 | bed28974f2f80c88c33bc408b1c3dbbb |
|
BLAKE2b-256 | 672ceba921b8ef8dc97461a74ae3dd74af9f791d8b8fa9571cd1db67b9353c3d |
Close
Hashes for pillow_heif-0.6.1-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be2e6561c660bf1c598a32eb8dc6e116169864efe8eddc9ba6397d8d1995b6c5 |
|
MD5 | 4972aa3ebab53af92be373f48ae40b13 |
|
BLAKE2b-256 | 2ff0c5dbde798bff355eeeef91b4675a785da4bbc14afddf3b772fee314bf38b |
Close
Hashes for pillow_heif-0.6.1-cp36-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 679097be4bb1070e60611984fc244e93eb8ba20fc174b59d9eb319f98c9c17c7 |
|
MD5 | b1f7a9ca518cde059ae2dd4dc2aee7e1 |
|
BLAKE2b-256 | ac27360a9bd46a0edfe79a01f733c4241316af2fa0c0e6d3998efb3d24f7e351 |
Close
Hashes for pillow_heif-0.6.1-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f6296443abf3aff4292f8021666a16077d3a5d9895e1acce8c73344f88eb0c9 |
|
MD5 | 52b9c36ffdb76c5e3979d0d5b68d5046 |
|
BLAKE2b-256 | 860ee0d02e9b4174933c4ce15582e2c8131bf1c679ba2ec5a6208e12d059affa |
Close
Hashes for pillow_heif-0.6.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2cb18a6b6be5d6f41326f3481e4cf186e129e4a106192be30d7aceef8fc2473 |
|
MD5 | 6c1663421f99fbf31cf2ec02e5bcb222 |
|
BLAKE2b-256 | 0b668739c87c2c3e98599b4ace1c1eff193586b171327aaadf6214e5993b4417 |
Close
Hashes for pillow_heif-0.6.1-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bca271171fc1b2da59cab1718171d140750c5760cddd664fd4a0b46b87644b68 |
|
MD5 | f7e432ca39e4b0a812605c32e27d628e |
|
BLAKE2b-256 | 8fa87f8f463f78843edb5b307a68b3a1c249c3c91a8d1b8e04579bae611f8526 |
Close
Hashes for pillow_heif-0.6.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22428d0ab75cf60d3e6ec61da54c11942487874d6f47585af3183a9fea862421 |
|
MD5 | d9b8c509162b390e4004c6241ff12572 |
|
BLAKE2b-256 | 0ff8ad15b77b146d088eda167751603c99e5ac70f97dfb1a8d727eeb8f559c71 |