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.
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
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.7.1.tar.gz
(8.0 MB
view hashes)
Built Distributions
Close
Hashes for pillow_heif-0.7.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0e6cc30381758aebc2272228d64a2102b3e8d6ba0ee9dc62e1aefd3aad5ef58 |
|
MD5 | 707e714fd359dcc6394895a06ba8287b |
|
BLAKE2b-256 | 8afd957a23529b95a04677d93ef585aa96e539d451e551bf657ecaaf83ca4fe7 |
Close
Hashes for pillow_heif-0.7.1-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56aad794bf33404e4c474a8be1ecd6e0783632ffe91e6bead2063bb3c0ed6a74 |
|
MD5 | 4eaf355029ff597e46694e2d17e3bfa2 |
|
BLAKE2b-256 | 2a4003f69c970a7f3523388bdb54ef1edab6132a1d8a74cf6104772364f4f328 |
Close
Hashes for pillow_heif-0.7.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d521a862deb312a37d07bd0a74039a470407e708bc0c8d76ab748331efc644b |
|
MD5 | 06fa595b167627f400541530969a4211 |
|
BLAKE2b-256 | 49a3b0dea788f11ae6923987baa5df3338f88fd144e00ce1888fd00682d84f4f |
Close
Hashes for pillow_heif-0.7.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61dcd9a9474445826f4c5fa685300c20a83591ce1b88294d67a63575723adc35 |
|
MD5 | 8abc88e9e54685bd8aed7224e671d733 |
|
BLAKE2b-256 | 3d80ec8a44820c2a61d2a850ad1f64c5558e415032034d653a0106b024f9cc9d |
Close
Hashes for pillow_heif-0.7.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62f6c08bf8034a53c5c0d912e3118cf5b864713222831796bd8339c5bd71778a |
|
MD5 | f4b547285cbc1ee71e4450eda6772d62 |
|
BLAKE2b-256 | 5c118feff4fe4a54da8222d2207ccf8d35424b61718bd5e4803e27e9483a3bef |
Close
Hashes for pillow_heif-0.7.1-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00e6a21628e61c97f68c1d80fdc9a7ad0cb7aa6b8b87ce535d7e8feb7e1ed687 |
|
MD5 | 3e5ca06df8d2d0e140795c03c98e7015 |
|
BLAKE2b-256 | 745e2e044fae087d0e18ec171df251e5799f16d8d945e8676f5a74701cc5402e |
Close
Hashes for pillow_heif-0.7.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49ed73b072001e1e01370a58ce6bcfbf4cd78219870733559123a6f2aa24bf45 |
|
MD5 | 11bad3161c269df41d85fc22091a071e |
|
BLAKE2b-256 | 018c51b14769859000ad485fce34e77208513ea2b51314cac042a79eab791cff |
Close
Hashes for pillow_heif-0.7.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa3743a3119f85bc24621181c4b4475b92cc842db4a9859dea0d8c26d8646ba2 |
|
MD5 | 0aebfac188389e6e9f14127d1afa94e0 |
|
BLAKE2b-256 | 2494b83cca7f0673284c080f85f078788a5eabb8a46ef2bc6a8ddb5ffea464ce |
Close
Hashes for pillow_heif-0.7.1-cp38-abi3-manylinux_2_31_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac29d0f36a85a9c64b57eb293c9cfe4ebbf85c37595ec520b91edd3483b2adf8 |
|
MD5 | a68bf91e2e90cf00fcf5ae41892ee4d0 |
|
BLAKE2b-256 | b3fbf7303d33987156cf923f0e73d9350a6da2c40d0d0e6faa6e34405683b512 |
Close
Hashes for pillow_heif-0.7.1-cp38-abi3-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5867ebab7d7ce0d10ae359d7b8bbe9dae0645f08006529fd7dfd0029e494195a |
|
MD5 | a04d77538205db3403cbad78b709bcb3 |
|
BLAKE2b-256 | 1e91292363ee8fff9f81dcd7806b5d84dcca4a5148ba00ec801157b19ba1bf10 |
Close
Hashes for pillow_heif-0.7.1-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 422bb3cf34e04cdb4c1b1405948aeb549d3e77a6fe6a07ea0d6eb468f8b0afa9 |
|
MD5 | 5e66063298ecdbbba0bc58a114d2f592 |
|
BLAKE2b-256 | 1ef8cf32e16f41da29dde26109638aedc0618658b71231c6fa3aff8d9fdd9fb7 |
Close
Hashes for pillow_heif-0.7.1-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7242ad92e3e490bb4adde01e2c3f68c23d9e2d0defe9aaa344117cbf7964d886 |
|
MD5 | bcf73d62cc11ed1d34e2d395b3c514b8 |
|
BLAKE2b-256 | cde45f3420f6796e37c8c68f60e89d098f23bc3aea7d9a5db3e96ad4e016caea |
Close
Hashes for pillow_heif-0.7.1-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9ef81b78675c4a37beaef7441a1da7db259c35af0fe24da78204395dbe6706d |
|
MD5 | 533fb4765642bf0b0cdd42520be93cf0 |
|
BLAKE2b-256 | 03dbf24b3a6a80541780ac7267711022bc17fc9644bb751ea7fc487670e22407 |
Close
Hashes for pillow_heif-0.7.1-cp36-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22f9c01848c3c40da310520cdd45cd268a1ee1493737374f28cd42821d612dc6 |
|
MD5 | 63564156e252b77210944dd3fe796cf6 |
|
BLAKE2b-256 | b07d029cda8dec1ab1de2ef8ab694388494dd5096dff0432c7beb5b06d4a04c4 |
Close
Hashes for pillow_heif-0.7.1-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d5e0360ee838e93f87b497c2e7f3e6620c300f2f6d933f40091f7596c7eb349 |
|
MD5 | 47c9ad9914d7ee030997f9847049a0ea |
|
BLAKE2b-256 | 71bfec475636a6687ed77838976acd85fb60789c93033e2b348ce62009d780dc |
Close
Hashes for pillow_heif-0.7.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaa1dd4ac00ad00e9f7cbb7051381aa5a6f3b8a61efe9c7b05dfc13610976e32 |
|
MD5 | 2d36404239267e73c10716e42eea140c |
|
BLAKE2b-256 | a0f912baf5e48791fa19b25450f4c5718c31240d732c13f3b98fea1cc8733e71 |
Close
Hashes for pillow_heif-0.7.1-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c3c19a70a3fc6ba7534e52bfa97fcd27cdfdd4e22f1aaafa939db02cc163579 |
|
MD5 | a59e85735fd3afc2e7143b08d847cbac |
|
BLAKE2b-256 | f7bea4ded54ccdfcdebcc170c71b446b2d996894ec437ff0ea7b7e2c7a3407fa |
Close
Hashes for pillow_heif-0.7.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e71cd886ee0e922e935dbb9b7c22352cc369e82b2560389973e83d43998ea3f |
|
MD5 | 8ae443bd2ce4dc2a8a8e5e743adcfe7a |
|
BLAKE2b-256 | 327c736eddcaca0d4388e923430074316c99c1273227d714c6e22539b0fa9ded |