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.1.tar.gz
(8.0 MB
view hashes)
Built Distributions
Close
Hashes for pillow_heif-0.9.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fab6daa73d32e4eb8c5285826e7bde2ab307c2c365ca75cf627ce43c40bc7dc |
|
MD5 | 176c1d6fa19a1bb8508d9a320c1f7087 |
|
BLAKE2b-256 | 36fb0a2a47fce6257c0867eb5b485470749d795e3d16a800905bba4103ca044d |
Close
Hashes for pillow_heif-0.9.1-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66a2740fb9bf14fd875c1ed2c38bf4a4d8d6be55c751d0f1d182b2a85efe0100 |
|
MD5 | 544dde6c493b3af975186d5d2dbb591f |
|
BLAKE2b-256 | 0e7cbbdec6e1b420d7b53c4ce796e7f70af76979780fc65838a7f04d3e9a0071 |
Close
Hashes for pillow_heif-0.9.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f812fb3edb7c5fd9e6a53bbfab8131c5d52bf12fc2959e67f772fed5133b9e8 |
|
MD5 | 4aaad83d0ca03fc901944727c0889856 |
|
BLAKE2b-256 | 37229388f7e501238769effb0c73d928ce52c745ddc478f0b0f09bb598d6ae0d |
Close
Hashes for pillow_heif-0.9.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 989427ae23ae6f0115c124b612b0d595128781d523dfaa2ee00c444f79d12d4e |
|
MD5 | 566f63e2c9012f1cad22ec3422940382 |
|
BLAKE2b-256 | 18788da32482e626eb04769ba5fb11ae8df0ac05a810d446950137ac6564f753 |
Close
Hashes for pillow_heif-0.9.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c02124ac806ece8496df3ff136b17faf13ce269a7a894dff651b67e16ecd8b75 |
|
MD5 | 90ceae0a601c91f0131f9d296085b52b |
|
BLAKE2b-256 | f32a07203d07e396c185635b21f821e1eb47bce97cba87d310ff9fea12df7d21 |
Close
Hashes for pillow_heif-0.9.1-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 202f0419cd674926286f6aa120e9e26bd8c77740b5fbcf60e2450706a48db4fd |
|
MD5 | 64566eea61b1cf64ba57d561a70374fe |
|
BLAKE2b-256 | 20f544ca438330a7003908bc6e299afb3e6547f1564d5823d4ea6fa7f6e34c96 |
Close
Hashes for pillow_heif-0.9.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34fb10924e1581fd05c8a6b3da6991c567cfcd0d72a3af0b760b63a59650fb15 |
|
MD5 | 9d0a45402ba6c22bf97240b26fa3cf75 |
|
BLAKE2b-256 | a22bc3428d3a84484f8698462a1efe7b5b7015d74dd01b6cb4eb78ac10984378 |
Close
Hashes for pillow_heif-0.9.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c73bc328116459c8600d84cb40891fd5634db30d3c30043f72670f78a191b173 |
|
MD5 | d40b2266b5a250d8948d8d00e22fab29 |
|
BLAKE2b-256 | d31317d1797dab07eb51eb8dd4a031211b3527c0e77e32d211a49d64283797cb |
Close
Hashes for pillow_heif-0.9.1-cp38-abi3-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3acfd84aee65e2ba3cf04c33a1a6a4256cd3b4e6e2a8d1238a2d2c5e07ecf7a |
|
MD5 | ec69919d86b41090c16d3f8378840c78 |
|
BLAKE2b-256 | 797f521e2ae61f7ea3c3a76d23d2ee0a7e45cba20debd968cef5da79c9eacde2 |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad2f7efeabedad5553ec51484c5d99b2f433d2983d881c1e5dfc9cc8c187e426 |
|
MD5 | 28447f46c3d0ca5fd0bffee42a57831a |
|
BLAKE2b-256 | d77924066438955f7cf8ae0b53be0231d62f5ead5754ed913f1ba33ff8798be3 |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baa1df2024c5ee8525a9cfa9c28f67dfe2c04670f410df21848d3b1a8541313b |
|
MD5 | 6f4cdddd81783ea2f20f38c4417522fe |
|
BLAKE2b-256 | 612136b60dc9c2efd8021f9e14fbfb30addbb10d2e8fe992ade5f804e0fa80c9 |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f69c44f87ce1591bb34f9730e67fdca08331e8df14e6e6099ff9278612501e0 |
|
MD5 | bf2c00cb192c549c278ec6fd5f4ffbed |
|
BLAKE2b-256 | 8ca1fc701fe0b0821b28d566d595fb3ac2fe10ab189a8ed74bd8f3829edb4f2b |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c77f38a5c2fc0274a294e451993ee5ad71b0326b1f9cd79176e98278c7414022 |
|
MD5 | f374dfadf8d454f8150f1431c246af22 |
|
BLAKE2b-256 | 5e7a716a67120edc0f1d246f6773de374a197c87b928c94a7038ae44ca61be85 |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0650367292cf274e82a78e33104f20fd9c3dec716aca54986b4601fba1c466f2 |
|
MD5 | af002b81d9ed04cef9cbd0294038b57e |
|
BLAKE2b-256 | 9213288c5860fcbc76c8b04f0ce4b8dbae4fee168ff11da1b1f91132ff9fe01f |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-manylinux_2_28_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c2ffde66965149f3e0434163024ee6c45e262c1c967d908f687e4d22bee8d9f |
|
MD5 | 458c251fdce6443456cf35abbe25a5ed |
|
BLAKE2b-256 | df03ee222a57d7f047ae133354a55b1d00fcf652defb0fff2e55754fbf332463 |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b9aaf4dc6153754b970439a1a547461771b4c60ccc465f0606a073b3564337b |
|
MD5 | 415f226a0d603cc137f018ee7ee596e3 |
|
BLAKE2b-256 | ffac49fe0f072308abb96b120c8c306749656e36fc96e3ba1f2474aef962ef1d |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2a61492dd749358a02e21b714f6949e7070016e583ef1a3d7804994e8853c9f |
|
MD5 | ce0722cedf520ade0cd8a56b964a4669 |
|
BLAKE2b-256 | 85ef01f9430d979039383b94a8f98346fbb605aabeec3df14dd7a6862d2ee1bf |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72099a2eb32eb9dd29918d914fd7d4d8377bbf8afea5d50f6ff35a03a5c1fb25 |
|
MD5 | 2585aa37b9c7e6b61dbe8986c7501102 |
|
BLAKE2b-256 | 37ddb8f0d035951492bf177a991f17036922bdb7519c7e0ebdfe0b237798e960 |
Close
Hashes for pillow_heif-0.9.1-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb2eb23f1fa9ecafa60dad6cb5fd7563980e087109a7ee58a55d6c569de283e5 |
|
MD5 | 18f4d1944ad535ac0ddc4d8ae504eeef |
|
BLAKE2b-256 | 1ab5a69eed18a4d4d6998d5a06d3d6da4d1575e2f3c46e9e623e03809bf22473 |