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.7.0.tar.gz
(8.0 MB
view hashes)
Built Distributions
Close
Hashes for pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a908ec284d6bf42a4445b261c1dd65393eb0ed7b1fa1fffc7f69026c4c1e921 |
|
MD5 | ab98474f5b2a291e0cfc4ee8865e55c2 |
|
BLAKE2b-256 | c3d07d6641fad1e618e57a7b13eb4712be994492027816128eb19d2ae2a739bf |
Close
Hashes for pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5799ae53b34ec78035ed5955ae90987dbf2ab9bba8aff0e42c654b3d5745aa36 |
|
MD5 | 5f7186fca2e43dafc02bfd2cf34a674b |
|
BLAKE2b-256 | c75bb5821968e9813b98cd7a030888c6f00975b69e7adc5695172aaf79fc49d5 |
Close
Hashes for pillow_heif-0.7.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c81b0c04df26feff0cb32948d05161fcb90f236766b3dd4bdf00f9c29e193627 |
|
MD5 | 7932f188c88f7bec1ed55940c5337992 |
|
BLAKE2b-256 | eb490a81bec4920a3acf561fbc1af2f103f7165773ee3ca4dd4c5de2286005dc |
Close
Hashes for pillow_heif-0.7.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31bbaf4129de58a2dec2ac2b62d24fb66ff56fab1d762b00d512e1421886cc42 |
|
MD5 | 0710deffed0c2c4db1c109cdbcd0a5c8 |
|
BLAKE2b-256 | 8dbaa1a5ad3386140b7a16bf7451556e166bb6a1ffd06995577173518348367e |
Close
Hashes for pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0684fd3908a96a9c17c0f11dbff7bdc936a54b12142028b071685f5efc0a3ec |
|
MD5 | 9f1d63b10fcbe0171983409089ad913c |
|
BLAKE2b-256 | d7fca209895c40a7002688c411725f7c22de312a5a55c01c0cf1cdca10ab0526 |
Close
Hashes for pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4a3acd9256c36f6a1899da922b2069227e8e8f20d89ce580b2ff0111516c721 |
|
MD5 | 3a4c6fe98ecc13b2b54669f66933c547 |
|
BLAKE2b-256 | 7d3f8a9781d1d0a8ca8a104ee1b8fca871fcc37113e90530580cdb45f73ba706 |
Close
Hashes for pillow_heif-0.7.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1bdb98daf42470fb3b9c02b84a618170c872aa58cf013f1ba8dcc2c077f0df6 |
|
MD5 | 4c05024a7433e667a480c5e8a57ae86a |
|
BLAKE2b-256 | 0b13e2ead4c1c6e8c9e2f961ae0b076a6dea2e09d3c840060c9d885e3f5f904e |
Close
Hashes for pillow_heif-0.7.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f294c30fc55688c7fc025bfc305e21e059bc43108a877f46045f84e0f07a3eb7 |
|
MD5 | dd7cb03313c20e622a94e0b8b885e26a |
|
BLAKE2b-256 | 82a2ebef55c99c32b9e5081aa2d9ec170a8a5d21bc4a11e3c10893f21c2adec3 |
Close
Hashes for pillow_heif-0.7.0-cp38-abi3-manylinux_2_31_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 043f36f5b672e2962bb2181279d6da89aed870deb23a0a22eb7160bf0ef60d91 |
|
MD5 | 5e96476f2ab5d53f9ab8af5b7231f998 |
|
BLAKE2b-256 | 5d086e550d7af6711836237c6b098e2ab3a7ce2ad20d4e85404ec40f4b4cf57b |
Close
Hashes for pillow_heif-0.7.0-cp38-abi3-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 205b11e41fb09312d584fd25b3691337c86da958824eba4c5a3bb7867dca6f03 |
|
MD5 | e4432e1f0d9e817ea0d9be7bf5c2fe9d |
|
BLAKE2b-256 | 4798fdba755e73401df9f9be27be948670a4b858d8490afc2053a1343ce95235 |
Close
Hashes for pillow_heif-0.7.0-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d5820d77c5a8445a3e9963982fea22705c555eceea3f237d5e4063b78a3c22f |
|
MD5 | 883900c36fac953884a64bac11541ea6 |
|
BLAKE2b-256 | aaec451117051bd36d7dce0a49b4c20ce72984b4e6e7040fd5513127315f3e1d |
Close
Hashes for pillow_heif-0.7.0-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7d261a33d3ea996c4ce573f8cb52b68d6b9824badfcfc7a306ecd22a7c31c59 |
|
MD5 | 1881f2a32ac06aea14f13aec0d415b63 |
|
BLAKE2b-256 | 293e0e404d776d231a187306efc88767af74026b447417a484a47f8a191dd3ab |
Close
Hashes for pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b81f2b66188aaab4c02f5a6e52a136e03c6a8cf39491a7d9b94317f29457c6d |
|
MD5 | 902bfa3d14ab8c47f27e14a46d39c0a4 |
|
BLAKE2b-256 | 6c437c5734cb186484f93138dc380d2fa95d5320f621004b8df97210eb2026e9 |
Close
Hashes for pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e26f032b934925df2a2bc275e19abb5737fbbba85f686dd6ac553011cd2b7e89 |
|
MD5 | f66eb225a504088c9901af3185200542 |
|
BLAKE2b-256 | 357b3568dd3e5ade8c5ded9f270cbb972190384aab7fbdf6486994b60616111c |
Close
Hashes for pillow_heif-0.7.0-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab717840e8d4bb4b2730aec99f28c6039a05b9f0629bf481e4c7d9effd2fb37f |
|
MD5 | 4ab99148e6368f684c34f58afe571346 |
|
BLAKE2b-256 | f4bce4675c062578d39f1c1d043ba99f854132a88a1befe32af007dd8c4f5e36 |
Close
Hashes for pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 895e7b6c32eab5a60352f5da8613be3b44f5ccef0fafaafbb63a6fd461a79c8b |
|
MD5 | 9649f592cdc3a8ef4f5a68390ef8137d |
|
BLAKE2b-256 | 79fb169880248dc3b19b1d86d66f396498d73a05536537b8c7ba7e9387d099d9 |
Close
Hashes for pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb79c49992c98b6bd059fd8f3440fb1ebc3b6b222f95c5e34f0e1c1cfd2c0248 |
|
MD5 | 408ea518f97a36318f32eede91476097 |
|
BLAKE2b-256 | 8c45aa8fb832aa86fb3229b5c7f2f782e67dccbdf7e7a004584924637cabaf8e |
Close
Hashes for pillow_heif-0.7.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80347012d874d0e0712b5fc3235bc9b914e8fb52f781b10d9389c2c8a691b41a |
|
MD5 | 0099dececa5b8cfb5fe223b12910850f |
|
BLAKE2b-256 | d5f2cef9a94de6bf016ceb4809f0c8b9022f9d50f2cecf89d349e3bb1ae76215 |