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 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.8.0.tar.gz
(8.0 MB
view hashes)
Built Distributions
Close
Hashes for pillow_heif-0.8.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b5a7ac091a4abe689084e4f973181dc43554ca66a2e21d8bc2e3fd69e1401e1 |
|
MD5 | ac89f0ad1c2f85902bf53a9d83e32617 |
|
BLAKE2b-256 | fc1357e6f6619e3f139a21a291f2087ac64b0cfd6af9cafe1e1afa367134662e |
Close
Hashes for pillow_heif-0.8.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eece9ebee204cfbb1676dd027e7f30182a63e1f7eb3dd849a3619eea05737c0b |
|
MD5 | 1865fe2b7c1f73004d8390f982dd0ed2 |
|
BLAKE2b-256 | 8ae98fdf37949634a34547a7b1afc192f32a1407c6623264b6f1f3c0fb537352 |
Close
Hashes for pillow_heif-0.8.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7839d80256e4e21da3f43124780217b61ff209f16e2fa8bf2cb7f693a9c7ffa |
|
MD5 | a3bd12d84dfee17fc1d30a2406b98106 |
|
BLAKE2b-256 | dea6689b00a25afe8c146d323e443cc7e311f3f94bce0d096f6673873aec623c |
Close
Hashes for pillow_heif-0.8.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b9046f9af06081087a5d8f53af4a027c98160ab26c5e32d4092ccd95cba51f4 |
|
MD5 | f71e4ad2b7d1669e969848f8f88678f3 |
|
BLAKE2b-256 | 4f5caab1c871893dfc181f084485b5f27cef8a4bccd192f2e7d337eb85932668 |
Close
Hashes for pillow_heif-0.8.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d10177a8d06bb0b82d5e96c7ec2f7fced49d88ee8516b1df82c6d6f46c5939ea |
|
MD5 | f608cbbb3511ce3ae4abd2b08f3387ac |
|
BLAKE2b-256 | f44c88e762692dc2bb33704060f04565aa1168514ae27cf1b9b2f4fedb416c82 |
Close
Hashes for pillow_heif-0.8.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f83fc7287d9f9daecf386a42b1b3724dac4ad43307cd3217e1f5cbfea8fdeff |
|
MD5 | b2f34b740cde16e90edf39951c5b1042 |
|
BLAKE2b-256 | 4dc90536a823bd0b17b22a313e363dbcd872680e3a6dcae344baee2caf0bf445 |
Close
Hashes for pillow_heif-0.8.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 871cf6cd29cf97ff8a206869a12149e014ba74202aa1f598b8923f3bcfb45457 |
|
MD5 | 998b47394a8d7fe9d5d43c052cffc629 |
|
BLAKE2b-256 | ce145f00b77876296147d372a572a1d2d29bb20e4ed35ba4e0105a88e927213d |
Close
Hashes for pillow_heif-0.8.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f8c4052575b73f5821790379feea99a06972d886bed6d487c44352744f32e04 |
|
MD5 | 773253c8fe411083b4d8e72c194015d5 |
|
BLAKE2b-256 | 5d21736312a643913d29b8885f0115539e1a7dd636681a772def37c67db906a1 |
Close
Hashes for pillow_heif-0.8.0-cp38-abi3-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 204df38cc3e8879394fc1bca818035a13ddee1d0622f522b96c3a0c8b7313b79 |
|
MD5 | 86b7571bf803e433aa5afc43f8fbbbc1 |
|
BLAKE2b-256 | ad6c1ee5bdfedc4b295eea5238e229ea5e75c2841bfbe2ee9b0d790354aa87a5 |
Close
Hashes for pillow_heif-0.8.0-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed0f86ce3c49c52e402bca35cae69867f1d4d38b345ab56ff1a0dfd745db947e |
|
MD5 | 3ff9882947e0aeb3f551995fc6c0ebe6 |
|
BLAKE2b-256 | 35b89992b3faa30351901d621eb41242cc8efd1c59bb2e64f2633d6715af3d46 |
Close
Hashes for pillow_heif-0.8.0-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e4f82f22ccfebc909644ccb949f041e2591f7247d5af375ab544f2ebe3c87f9 |
|
MD5 | 1ea8b7eab414e100a46a02946960ebb7 |
|
BLAKE2b-256 | 2e4b4f573a2cfffafd6c0f305e93eb08d692f32a6c5d74d5eea2f2046e5d3ad6 |
Close
Hashes for pillow_heif-0.8.0-cp37-abi3-manylinux_2_28_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e727e8a97e1dc5dfbc4db5563889fbafb27dc017723ff4f07bef6afc3d8e41dd |
|
MD5 | 341b8e1f60dc2e2631dae14ea541d25a |
|
BLAKE2b-256 | 02cfef842c28bf807973a534b75442f55c75c645345b1402398cc31cc106b8fd |
Close
Hashes for pillow_heif-0.8.0-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c7b84c09d6036f7607a0651f753a39255e2bbf0b360cfbdbb1407241a779584 |
|
MD5 | d1ea94d58644cb610b8a3a55488952cc |
|
BLAKE2b-256 | c19d159a587ea03570c4b9d379823c4e83b2528c9400315db1d0a761886ac966 |
Close
Hashes for pillow_heif-0.8.0-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 341c6d6021741f9019bf049f5093d2195a7c3dd7ccc18509be644ee9ac682db6 |
|
MD5 | e9a8f8456ae2e7c90adf94185e995b0b |
|
BLAKE2b-256 | 13b3d9b7b2f7318e9573ea47d1300e9b517554a1836c4e704d644c60babbe0ec |
Close
Hashes for pillow_heif-0.8.0-cp36-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bb2885266300a352796a2198243a7c995178f62716e09976a91199de0889179 |
|
MD5 | d5b91b72836690dbba194442fc1cc144 |
|
BLAKE2b-256 | 43b98dc1cd4a7a064b54d488c18e8b3281ed5f732beeabd98f00f6cbde47a0d2 |
Close
Hashes for pillow_heif-0.8.0-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 277a8f5e92cb07566cf8204ef42660836b11ca0c3149e8947b4e05393d573899 |
|
MD5 | b0ce4e6bc7d19de72486036ff506cd38 |
|
BLAKE2b-256 | 6ca622c80b2b5bd0a39faaa0da340d62afcce183d5942ed550c517a4a7c859b4 |
Close
Hashes for pillow_heif-0.8.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c0cdcdf09da3303b96a1ab7a47bab5c39b6022cb1703a071adef14ea0b33e6c |
|
MD5 | 5247bf13ee13161cfcb8f2cb0f2aa4ec |
|
BLAKE2b-256 | 844fd5a99ddd21b0e754791f742b813c840cf41c5fa94c7579132648af72af07 |
Close
Hashes for pillow_heif-0.8.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cd6a2fbba1520eb4ad442031d560fdbab3d00ae53a912716acb9b87febb85c2 |
|
MD5 | a57589d2608a42f777645f80a558f614 |
|
BLAKE2b-256 | 2aa341be66d66a7754351263b41fa078268400393002df6639961bacc6d2cb05 |
Close
Hashes for pillow_heif-0.8.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e63c8a2f894aa44bb0f79a6ecebe11753ed24e27a432ce4630f7b6dc55ba27e5 |
|
MD5 | 6a15278c5ab0f14736f71a328b83675a |
|
BLAKE2b-256 | e7641daefa5211e84a5a7dc6f7706ec6736cbdb5a75bce5f91795dd305caaf0b |