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 HEIF images. - Encoding of
8
,10
,12
bit HEIF images. EXIF
,XMP
,IPTC
read & write support.- Support of multiple images in one file, e.g HEIC files and
PrimaryImage
attribute. - HEIF
native thumbnails
support. - Adding all this features to Pillow in one line of code as a plugin.
- Includes AVIF(x264) decoder.
Install
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.heif", 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.
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.5.1.tar.gz
(8.0 MB
view hashes)
Built Distributions
Close
Hashes for pillow_heif-0.5.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27a14594b4d092ca112ab498cbc4fd161be9ea5e622df0c01360f4e285aa4dd5 |
|
MD5 | 5c2dc9de8d2092e9c32839548255878c |
|
BLAKE2b-256 | c19053600c66d94a99c8bdd2b2439ee913dac0ff2d9b7f472cacc63fa453435c |
Close
Hashes for pillow_heif-0.5.1-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 508355f6e476b333a35447a1c62d8111dfbbc83842d30cf0cd0f27a7c0f71ccc |
|
MD5 | cdc6ee80998f9816f6127e7bdb6ef766 |
|
BLAKE2b-256 | 3a9d179e7a3b8e9995e22ee581dd7cce4ab541169e48be081dbd91144f0067ba |
Close
Hashes for pillow_heif-0.5.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d49a86d90a6385c3cb719ff0f8ca2d389adfed388883526ffae0ff8197f46947 |
|
MD5 | bd06440c32df15b7c78b29099c982acd |
|
BLAKE2b-256 | 1c707fd64410b9a8290d87dc4bc8aa0425ff29a9432f3699937fc208e0423bd5 |
Close
Hashes for pillow_heif-0.5.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f4e80f414985003fe5cbec9303a71507cbbb683f11e88690d61593df68cd44b |
|
MD5 | 5826c6afd37690b0bbdb148fe90a94e4 |
|
BLAKE2b-256 | e183dbc755b8fa73747b03ed902ebb022d66782cb35067b03371e64642eadeb9 |
Close
Hashes for pillow_heif-0.5.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcb7177c9c66649740b56e7d784eda36ae877ba52cc8b88a389e1ec87f29e1db |
|
MD5 | 711dbb222103a13397fb462a86013975 |
|
BLAKE2b-256 | 14e717ab5d9bfadf2f3c71cca662a382f873a9a2b1ee37d80fea300a7d992ca8 |
Close
Hashes for pillow_heif-0.5.1-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dd2ff0746d4fa6264f9fe52fea30f610e2908bb501c4e2fc6c9176e899427f6 |
|
MD5 | 85bd61cd7cfe5c15bd003b258aedb6b6 |
|
BLAKE2b-256 | ace2a5dec9129f6c1aa5b93ae1e35e5859b46849f338c5e05ca546f2bcc99819 |
Close
Hashes for pillow_heif-0.5.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bd3f7422f34e6297da1413cedb36d52e72a82e65442fcac7efbfe80d6cc73ff |
|
MD5 | 2d075857b37a39d3916db3eca229c9c4 |
|
BLAKE2b-256 | 816dbf7af0b1f99ab09c9f6d57ed97bfac4d917e9ed29a849372312571904aa7 |
Close
Hashes for pillow_heif-0.5.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20eb5ca096c73112edaa281e4afdf321718caf69b0fe4a8f1137298d8f6cc5b6 |
|
MD5 | ec048cc91dcbc5b0a62768c76812fbeb |
|
BLAKE2b-256 | 2d7e2aed72d036b74cc550401e0f438c62c1cf150c5b6ad008ec359972dce704 |
Close
Hashes for pillow_heif-0.5.1-cp38-abi3-manylinux_2_31_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc5b4a2ff3739db6e184dfa471d1ed70f06e5409e165876df67098807a9b822f |
|
MD5 | f9540b03dff82d9393de392b5dbcf3cf |
|
BLAKE2b-256 | 5c1e9caf108923df7393f40f803b7aa30f37d63e8466644450d82f88cb457226 |
Close
Hashes for pillow_heif-0.5.1-cp38-abi3-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1a9fb1ea66ee107d1a19453382b0816b3b13607d9098597e81217b936ad936a |
|
MD5 | 428a1a434ff2f343d7ca45f32fa3e759 |
|
BLAKE2b-256 | cc97cfedd4fb23ac1381d24517dc928ab39228976b23d6e3060e20fcabd63096 |
Close
Hashes for pillow_heif-0.5.1-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e653d556ad16b2362b9db1bd3abb89fde6f5f97c568972285c86fcb274f04dfd |
|
MD5 | a38900d42670e7524f9f893e82f41aa9 |
|
BLAKE2b-256 | eaa98fb028a2b2d21ec20fa647769a7b662389b1bd28646020aa3ef4242a3f09 |
Close
Hashes for pillow_heif-0.5.1-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3356a321c98fc4a27df2f1165df753ade59f9f0d0269bf6b02b072539653b5a0 |
|
MD5 | 6a55901223a6441c3ff8cbf62afed739 |
|
BLAKE2b-256 | 3da191bff46b4042505fa1ca07c300e5da34882b70312ee707e9b7f08bde61a3 |
Close
Hashes for pillow_heif-0.5.1-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e7a6a82e7fe78b88aa408e44a9995361b0c96d2f5eeb0114d748333d020a803 |
|
MD5 | 419e315bfd5fc52a74f189ead9cef765 |
|
BLAKE2b-256 | b069f55699f8d679c60fba088a142e7f3866627dbe9b86c23746f6a664da4829 |
Close
Hashes for pillow_heif-0.5.1-cp36-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04e6dff69b9c75bebaed3b18d1ba58b695e4ec8e86f26c7c58c39b27614526d4 |
|
MD5 | 2e6f6d713f273a95c704a016a3237e82 |
|
BLAKE2b-256 | 21d3a0629d81a31052fa4bf9c02dca2b2e5138df882dc9e728426ae2399b8e19 |
Close
Hashes for pillow_heif-0.5.1-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a945adaddec1d213f0d35d8185fa4b64d71dd57b36c3ad2ecc06769a192c0cb0 |
|
MD5 | 7e93c38fa8a0d43f21f110b2a9aff325 |
|
BLAKE2b-256 | 80b601a8fd42c43bd2c2600c396873ce01ae9f1e046f367e5f02b99399ceade3 |
Close
Hashes for pillow_heif-0.5.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0067c2cb804121c3ed443332f895b2914d588b1b3acea949d88de0a128fdbc25 |
|
MD5 | bb8002a84f30c872acfbb0ac54defaa4 |
|
BLAKE2b-256 | c2eb1e48a56e68c1003928f7b174842270dc1a5836a23988de228ca67a80ec63 |
Close
Hashes for pillow_heif-0.5.1-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed8545caf7b12b51cdeee9d00d160da23772dc9d87577e6c91539a3e26bec0b4 |
|
MD5 | c314b3696cc0b989da8ab0fdc524f0d2 |
|
BLAKE2b-256 | 4e3c0d06bbe5db669b55c04503ad0bdc4603c2c93e062ec072dd6d4280a3b619 |
Close
Hashes for pillow_heif-0.5.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da7dbc7175a20ae67efa611943957fbf097b3801d5a33deb189e675cd8a4f42 |
|
MD5 | d41a095f7f3464ed5781b92a42f0a86b |
|
BLAKE2b-256 | a555011d59a9fd185766ae12041e20ef443fa57259e857b640db395dbf119ad6 |