Python interface for 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.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
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.9.2.tar.gz
(8.0 MB
view hashes)
Built Distributions
Close
Hashes for pillow_heif-0.9.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a545ab79cc995dd02b505773da8266fadf5b3c0183db5a71c26f8cb9c121ce34 |
|
MD5 | 067d20a99d0201ba2533ac412373cd92 |
|
BLAKE2b-256 | 51f0e0784b6674b64cd4a09f35b5ece031979d8da1848276500fadbb3b73b1c5 |
Close
Hashes for pillow_heif-0.9.2-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cda7e968d49d9d3c0cf0cd92cb08107f432040e82097abdd5109d849d85cb8b0 |
|
MD5 | a5e9db1a008fb3513144713aeb8297aa |
|
BLAKE2b-256 | 35210fcfbb6717782077b44a9c6c4b2f493f2bae79ab6a6ea04a183ed9e6d6f9 |
Close
Hashes for pillow_heif-0.9.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d6d1bef96b0f2972f73d37bced84d855fd1aebea430df49bebb5d958f1c45cd |
|
MD5 | 920d558b0e683ea01d6ca81560d663be |
|
BLAKE2b-256 | 69b0e9af641eaff1079f36645ab416bd7a8a1fa6e0cc41a99ed468173de4d111 |
Close
Hashes for pillow_heif-0.9.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84daac4f8114e9ce9e431abdb219f71ac4d87bb2d00253f6b54b0a23aca87e83 |
|
MD5 | 1ea6328e5fbf770cb6b0fbdb2b3213b5 |
|
BLAKE2b-256 | 41b5889d67860a541f792a227fe616df68e44555db2bdad91fec8638aab30c14 |
Close
Hashes for pillow_heif-0.9.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 299b8e34724d5677fbb4d841f7fa5781afb6e667cc0a4e81349a3b23ebdd84fa |
|
MD5 | 898f7326e015d701234d587b317cde45 |
|
BLAKE2b-256 | 0ac3b79255bc00eedd4425bc7d8bd470b66fcb7fd45ecc42225e594ccc8e467d |
Close
Hashes for pillow_heif-0.9.2-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00a1d940f11c2a774dc99e559408927c0507498c4ab5f8e7340bc6db47c7d157 |
|
MD5 | 3f608ae261d894af616da18f30e27e01 |
|
BLAKE2b-256 | f7a778015625090b2062c6ff9987fbee14a3ecefd3fd5e6fdfef86482393e3e2 |
Close
Hashes for pillow_heif-0.9.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 676c3c85a38ace0a01a7150c4f5300d5c22a7ed3c6d68e36503fe17519959e41 |
|
MD5 | f29977c368a36e3bd5419e5a0949d295 |
|
BLAKE2b-256 | 4a11ca9fc187b03182337573755c882ed2d8249b04e376caa31bb802d2d27c81 |
Close
Hashes for pillow_heif-0.9.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0a431701cc8413167f9681bb1af22a283136c0818358e566c6709c5f5cf0444 |
|
MD5 | 22690a7655dcf00a99ea11630f09988e |
|
BLAKE2b-256 | 284bab2e710b5a40ee8e3cfca859baa43d57dbe01443fd59e5dc1d19888e30fd |
Close
Hashes for pillow_heif-0.9.2-cp38-abi3-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73f22ef71305f3bbe4e586a943941ccc82e1753b054064cc44018d36753c7771 |
|
MD5 | e1c3a8dcc2c3a1bc6bc588f217b57946 |
|
BLAKE2b-256 | 5a15bfeeb76bca87ef3a953dbbe716b69048e94fb3e8e597d457eef585502c87 |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fb4da0451a150ddfdb4b5e2b86e427a477f015445d240757bf3346337f32879 |
|
MD5 | 98284ca1cb7543e9fcb358fc8221b38b |
|
BLAKE2b-256 | ffb1c145f30b2a69c137949e36d6f47023374a1046c976f0bfd6780b4cf0c0b7 |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10b1d776f9b61c4237611cdf7ff54cad2e7bb259b13dc0e7959f55e9094da289 |
|
MD5 | bb86c419b780d0e6d07da8592cc2f3df |
|
BLAKE2b-256 | 2aca58e4bd2035ea0aed642b94e11c8d9aa580ff97ec43e8ca6dc04848d2a777 |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8db0af75953e855c4856321ce35088cc015bfba41dbfacb456d4476e5b17ace |
|
MD5 | 1d6de15c836e67c19c468c87b1ea4fef |
|
BLAKE2b-256 | f8e41610e9a6099a98bf0346c4da669b851a11bb342fc97efb6bf97e4838c455 |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60b333df8e3573db2a72d20838d9b3c0b42f1e7898ef68a69557219a8626fbb9 |
|
MD5 | 245734ca59f0ff53a998c8fbd09463ce |
|
BLAKE2b-256 | c98ec66f83becfd3ce972c8bd2336d7d3d9a8f974eab6db904ea21def073359d |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af7d2164a68c37953694b9332c480671b5909cbd3e70433a2d5f70f571bf7f7a |
|
MD5 | d8f583063bd5fa27f8cc026847affcd4 |
|
BLAKE2b-256 | 96752f10376785563a6f313c30184c1cf34fb7db7981555afb563813aca9753b |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-manylinux_2_28_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b5da2ac56f48fcce14a3e1bc2326fd01fda282299f3674ed75c1f428c425a0f |
|
MD5 | 9f2b0e7bca3025ae6b04144b86213d04 |
|
BLAKE2b-256 | 2b50de6264f6b5fa042477ad6da3fd8688b21900c09c200f90e75b3be5efe5ca |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04be939b7f05974b7f02b5cf5d9a43b947e85ea7225eb43a678bffc40bf55c28 |
|
MD5 | 02c8a9712fb6dd8f9b2a183b5ee97280 |
|
BLAKE2b-256 | 066acff54af28df780f3a0633e98202fac8672730b0abb00d12ea1aafa15d672 |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03ce735dd0dedf64e5427887f16d455083e929c506fcb35e08352bc60c9a3684 |
|
MD5 | 07fd7c88b25ee924e6c2b50fd5e35507 |
|
BLAKE2b-256 | 2fb0b2d700843625aac7a869cc50b604cb5cd68c1137ce2b83d3c99da37d8f61 |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac7a58fb9dec9e2dbd86960c4a1ea3a0600dadc407e4542359fefcf390a03114 |
|
MD5 | bb81440d6768a3c218443697d4883e5a |
|
BLAKE2b-256 | cd9ac7635d187dd98d51726098bc9a9b75083d6e3b85cbc7cfcc0c8bb90d7428 |
Close
Hashes for pillow_heif-0.9.2-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e74de4b3965e84314dcc86b33fb5a6a4b970428259ef18c9778a5d84bc57107 |
|
MD5 | 4795ec4d8438711af576a6329b23d2d8 |
|
BLAKE2b-256 | 2a80362bd7e7d71c07e5ee956ebc60f4f372027e2474a9b2d665279200525df7 |