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 | ✅ | N/A | ✅ | ✅ | ✅ |
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.0.tar.gz
(8.0 MB
view hashes)
Built Distributions
Close
Hashes for pillow_heif-0.5.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f876833499bd678630733613f8ba2dffd75f396b20e0d9f81cc102a1cffbce20 |
|
MD5 | feef565878677c0db26a5af7ea0104e4 |
|
BLAKE2b-256 | 8ce9a752e37d346b42a0a81061eb031f4eb009c7fefd82319c3f65a3a18c02b0 |
Close
Hashes for pillow_heif-0.5.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91a1d68daf566bb67529bb45ffc5ef962c94736e6e9bbed76c225861c3bf1994 |
|
MD5 | d057b448e76a837d77b573a1ae47f8c2 |
|
BLAKE2b-256 | e3aafd82b210ac0244f184a2ff81354f4cb82a1af5a7a5db0f7d245e47bc7707 |
Close
Hashes for pillow_heif-0.5.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb6dac157d498f32175f3f7a6c024db84b6dda72ae913472b662c8873fc4b4ef |
|
MD5 | ccdb3356d17161a077930136603f2be3 |
|
BLAKE2b-256 | 8caa998bbfd34a9f02ebc511f95b8b3b0d03ee3983e1c5689f8a29993ad5905a |
Close
Hashes for pillow_heif-0.5.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0f1c64ec90ca14234d8a84c9ac0c138db0245da5ebd08885445c46bbba3ef86 |
|
MD5 | 3cb3efae68473de4d6eacc23e5215c1c |
|
BLAKE2b-256 | 7faaa0960b094401aa084103dd525261e1511b354b58ad470249fb0f4a5f1df3 |
Close
Hashes for pillow_heif-0.5.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 535e9d0316c3285d7bbc448c062dfbe08b79f202e016cc7a9e7e434033ce85b2 |
|
MD5 | 4cf706d25c583342e5fd81a474a8a0d0 |
|
BLAKE2b-256 | 94aeba137814843bd197d64ff5cce47b57749d58977be99f975813a7f590fd64 |
Close
Hashes for pillow_heif-0.5.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdffed0052e2ec9f36a513cf255d1784befe7cdd86751447b9dc058ea17c6464 |
|
MD5 | 99d9d3be816dc4b566d8fa9ce3a02fb7 |
|
BLAKE2b-256 | a2c196309caeb38abee98dce10a30caed20bfea3db5ae6085d8f684df063f443 |
Close
Hashes for pillow_heif-0.5.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbc9492722355c35d9ec7ea9f270bd7147c2730c4fd1073f982ea7ac95bef0ae |
|
MD5 | 17f4961560ede826399d8834e8c2f2ea |
|
BLAKE2b-256 | 4a22f152a8e61287b91bf33613a58bb77e9877aa8ad9e05cea3c3bb3dbbbb098 |
Close
Hashes for pillow_heif-0.5.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28f394b5c01f2669c4819c46625e888c72d4d85abba01267d13d3fa9f78709a2 |
|
MD5 | 8a12dccaef28648b09a46e62ba019adc |
|
BLAKE2b-256 | 05a02450928e2fe3cd4862c78b128593a5f498507f4be232dd6fa249cd3d3ee2 |
Close
Hashes for pillow_heif-0.5.0-cp39-abi3-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d53686f463bc9bcd312a8ee95b5940c378347eea41486fffe7686b6d83b95249 |
|
MD5 | 29ce54be0626bb46a1532338cec53b8e |
|
BLAKE2b-256 | 24ada195224a3694a6043fa31faf239524015d05353243acc8105e8026665401 |
Close
Hashes for pillow_heif-0.5.0-cp38-abi3-manylinux_2_31_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdfea22cf4eb0c0a8fc4ca423159f88db921e08ef8d1c80963e6eabdd1443242 |
|
MD5 | a328d2e7e316d4766e26a87edb515d9a |
|
BLAKE2b-256 | aa645a0b94fbaf082fc4ce96e3b9edbc1e8eb499394c3f08d30dde8385e199db |
Close
Hashes for pillow_heif-0.5.0-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bca11a7963945683750a59f766d64c62114d57456009763c97c4788c37637db2 |
|
MD5 | 0593fc6412bd52d7114e1bd24ed16069 |
|
BLAKE2b-256 | 37cf6ec2762417378a2f2d6a2501bae6d2f364dc25a8ed49fcc2d7d0cdff31bc |
Close
Hashes for pillow_heif-0.5.0-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7528cefa07f0d2825f366b4f4e69d22d1ee7cfc1c2af4f4099a36350910bbe68 |
|
MD5 | 41ac65f9414561fd635b1377557958cd |
|
BLAKE2b-256 | e235ae3862a433986f164121c2a00ec940b512b47f2bc3df89bb657550285fd8 |
Close
Hashes for pillow_heif-0.5.0-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95d6309d3cefd0fe2bc0c2c0341dafd9aca80e547e0933bc94fa3f8712186bd3 |
|
MD5 | df23ce20cdb3d6f96dd1239262cb0874 |
|
BLAKE2b-256 | 872cfb82261abbdda36973551a38df1fc07175d0f21ab64ece89251319b8b985 |
Close
Hashes for pillow_heif-0.5.0-cp36-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0db0d256ce8fcd6f885be8687f6b202c4f13bd20b49118692e501056aac77c5 |
|
MD5 | 8b1128dec25d2f8ccdd29da12ee2f5a1 |
|
BLAKE2b-256 | 028d6b3bd3c8ce7733269e6f6346d36285ffeef2f8048a6a6cc7ff82bf379795 |
Close
Hashes for pillow_heif-0.5.0-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c90f5698699c6c8bbc631be479580d5a4ff112d6013797c57e7215b4355d1f2d |
|
MD5 | 32dacc0d5634a9e2c0d925ba2ebf49ef |
|
BLAKE2b-256 | 81a8f2a67fc6b209e670e4885a21a729071300588886a786b5f4658bc1dc0610 |
Close
Hashes for pillow_heif-0.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e253c6e78b5eb466a364c366c0fa6fdee8c4c84bc640375071f8f7f5c8f500b |
|
MD5 | 2cb90d7ca2003fdc5e701ec1f88d74ca |
|
BLAKE2b-256 | 2515e97575942355019c53f8c3ccee3ff6a1f2711403dd6216e2ae37a6714516 |
Close
Hashes for pillow_heif-0.5.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fc6ffbf85e6a41c968689ea840206b236d3417815330e7e32642b1976588d49 |
|
MD5 | bc5f699aaeb2fe822dfb0e7f5b329836 |
|
BLAKE2b-256 | 7d3e43c4a416a56ecad549853581d96ee992fc0f69c2777f86536992d4cedfb7 |
Close
Hashes for pillow_heif-0.5.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba87c5cfe2bbaff734a705bae99f883639c5f2d7b1683f9fccb33f79db5f59c6 |
|
MD5 | 5ee2f38a1a292f9bf99dae3638aa08bb |
|
BLAKE2b-256 | b585c9c8123f0f5c35b593a37fbf6d8513291b622221ddcf659f7b366b4200c0 |