Python 3.6+ interface to libheif library
Project description
pyheif
Python 3.6+ interface to libheif library using CFFI
Note: currently only reading is supported.
Installation
Simple installation - Linux (installs manylinux2014 wheel, doesn't work with Alpine)
pip install --upgrade pip
pip install pyheif
Installing from source - MacOS
brew install libffi libheif
pip install git+https://github.com/carsales/pyheif.git
Installing from source - Linux
apt install libffi libheif-dev libde265-dev
or
yum install libffi libheif-devel libde265-devel
then
pip install git+https://github.com/carsales/pyheif.git
Installing from source - Windows
Sorry, not going to happen!
Usage
Read the primary image of a HEIF encoded file
The pyheif.read(path_or_bytes) function can be used to read the primary image of a HEIF encoded file. It can be passed any of the following:
- A string path to a file on disk
- A
pathlib.Pathpath object - A Python
bytesorbytearrayobject containing HEIF content - A file-like object with a
.read()method that returns bytes
It returns a HeifImage object.
import pyheif
# Using a file path:
heif_file = pyheif.read("IMG_7424.HEIC")
# Or using bytes directly:
heif_file = pyheif.read(open("IMG_7424.HEIC", "rb").read())
Converting to a Pillow Image object
If your HEIF file contains an image that you would like to manipulate, you can do so using the Pillow Python library. You can convert a HeifImage to a Pillow image like so:
from PIL import Image
import pyheif
heif_file = pyheif.read("IMG_7424.HEIC")
image = Image.frombytes(
heif_file.mode,
heif_file.size,
heif_file.data,
"raw",
heif_file.mode,
heif_file.stride,
)
Note: the mode property is passed twice - once to the mode argument of the frombytes method, and again to the mode argument of the raw decoder.
You can now use any Pillow method to manipulate the file. Here's how to convert it to JPEG:
image.save("IMG_7424.jpg", "JPEG")
Read the entire container within the HEIF file
The pyheif.open_container(path_or_bytes) function can be used to read the HEIF container from a HEIF encoded file. It takes the same parameter as pyheif.read()
It returns a HeifContainer object.
Objects
The HeifImage object
The HeifImage has the following properties:
mode- the image mode, e.g. "RGB" or "RGBA"size- the size of the image as a(width, height)tuple of integersdata- the raw decoded file data, as bytesmetadata- a list of metadata dictionariescolor_profile- a color profile dictionarystride- the number of bytes in a row of decoded file databit_depth- the number of bits in each component of a pixel
The UndecodedHeifImage object
This is a HEIF image that has not been decoded. Calling the UndecodedHeifImage.load() method will load the data and the object will become a HeifImage
The HeifContainer object
The HeifContainer has the following properties:
primary_image- theHeifTopLevelImageobject of the primary image in the file.top_level_images- a list of allHeifTopLevelImageobjects in the file.
The HeifTopLevelImage object
The HeifTopLevelImage has the following properties:
id- the id of the imageimage- theUndecodedHeifImageorHeifImageobject of the imageis_primary- is this the primary image in the containerdepth_image- theHeifDepthImageif there is oneauxiliary_images- a list ofHeifAuxiliaryImageobjects
The HeifDepthImage object
The HeifDepthImage has the following properties:
id- the id of the imageimage- theUndecodedHeifImageorHeifImageobject of the image
The HeifAuxiliaryImage object
The HeifAuxiliaryImage has the following properties:
id- the id of the imageimage- theUndecodedHeifImageorHeifImageobject of the imagetype- a string indicating the type of auxiliary image
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyheif-0.8.0.tar.gz.
File metadata
- Download URL: pyheif-0.8.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9b4c11ebad482fc25a0804ce295b44b660cbf7829a228f56b071f325f9e0de4
|
|
| MD5 |
5e84d911b7733d426170742b03d994c2
|
|
| BLAKE2b-256 |
ec11d63f215d8c9c416409e2d665bf7594a8886780629296b4f0d35857561c9b
|
File details
Details for the file pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.2 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef3255c5dd9062f38fea0f4cb41f3192616307252db448a2064f8bce31640112
|
|
| MD5 |
0e20a7f4b22e6bb93580bb1d6a4f7eba
|
|
| BLAKE2b-256 |
15b56cbe1e0bcd0db171e57a838fbf611d937ce120b87a045b6d4a868d85f394
|
File details
Details for the file pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 5.3 MB
- Tags: PyPy, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9f1c8e3158b98fc82b3833e7358f6ca0ef9d50fa93d20993925917e9189bbc6
|
|
| MD5 |
34e7088e2a39f13cfe98b4d8bea19f2b
|
|
| BLAKE2b-256 |
35175a5a70da5b6dd52937e38259e65180414e4c5625717b139a6f7aa30a79a5
|
File details
Details for the file pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.2 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b896eebf440ea826893a253c8f8a5bbd245f96a1613858d7c4ec310420ab9cec
|
|
| MD5 |
b2c037d815b40f5a788d9ab6e741c341
|
|
| BLAKE2b-256 |
4c0dcee50b45e7360226e6c66f9b65fbb3a354ab7a35dc54e335d1cae9f03dcc
|
File details
Details for the file pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 5.3 MB
- Tags: PyPy, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39214792559eab90814f9551540156550619fc6f8f0d794091488563577da5ca
|
|
| MD5 |
247ed0ccba9d0e459b70cddcab41b775
|
|
| BLAKE2b-256 |
8d97a180a87119f81f06d032a0530f4636e1c1e75d9589c8c6b915d80cb0743f
|
File details
Details for the file pyheif-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f98f4b1d37705418d77ef42a8ebf95b510bb3e0a9a2d9f0824f6eeb751c9e7f6
|
|
| MD5 |
b77316811a749bf8eae784e76f27c94f
|
|
| BLAKE2b-256 |
87c41d0e82766657b3839993ffe411807a08623ff9affd7275533afea3cb377e
|
File details
Details for the file pyheif-0.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac5ec62a90c4f9f96125aaebd6ac994b95895ace4427ecf34752951e1d34be96
|
|
| MD5 |
3e529a7fedda111678f5043cfe11795e
|
|
| BLAKE2b-256 |
fc4907d1c047e52fd4de1474759e202b2fd7ac99e945db0ce149af2f85be7625
|
File details
Details for the file pyheif-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c8723ab28ca9f42e0f25a29008673654e062edb95b26dbfa3e397e6cc3d56b8
|
|
| MD5 |
7069a8146ed5b56b2a1013a561b614c4
|
|
| BLAKE2b-256 |
6fa92514a4d53ed5712bdda42281d0b3b0f652ccd35ba08b66039510592cf67e
|
File details
Details for the file pyheif-0.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01c94cc524446d6e23a2726d4cec94c764b277466cbeca4d95e083390b09ad34
|
|
| MD5 |
9397567376aa90ecb82a8b5a244c6218
|
|
| BLAKE2b-256 |
62e752450ce4cf5e682ea8950f86725dffad461ca8b24c9215ac76d61e2d8392
|
File details
Details for the file pyheif-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e93ff599eba671718e9dcab2dcd4efdbcbdbe4bcd31bd9477026e2ffc39125b2
|
|
| MD5 |
0735612d512f4fc15530e5d4a4c43b50
|
|
| BLAKE2b-256 |
d29aec37ceaf6b93a23c33c6080a7ac2570148d0a51fc4db733dc2ea735526de
|
File details
Details for the file pyheif-0.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a9df316c695c7a4588633486c5f93508474653488dbcb8c968dc0c611875106
|
|
| MD5 |
d8f1fc8d85b5f95faf27fb158b896df1
|
|
| BLAKE2b-256 |
529840d97d38454f6708db7b819b8c206e206e4730183860b3a3be56fa44cdab
|
File details
Details for the file pyheif-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6e08cdd85f638e134cbd94006631d8e5263002a3f8c4f44b1f94626fb0cf4f3
|
|
| MD5 |
06f47bc22bb39de04eec44029440c638
|
|
| BLAKE2b-256 |
1142b0fac6f16c96e54039bc66578aa559a06d0c24c413e9f061dc2d1ac1637e
|
File details
Details for the file pyheif-0.8.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adba452e061b4b1edf57ad561daf69f3e67de4be42088885685ef4e6a8dd9baf
|
|
| MD5 |
cfcc385a95654cb3833a7b84ff347ddd
|
|
| BLAKE2b-256 |
25ed108eabdcbd8a12ac31b4979dd9a9bfd8342590db27037ecba3ce5a773276
|
File details
Details for the file pyheif-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
272d08f3308dcac1ad12b100f0d433f28e4f6e2aef0c28feee1d4b2bbf7e8f81
|
|
| MD5 |
7260c4dec1f0f16e11aca5f4028785c0
|
|
| BLAKE2b-256 |
391b1519742ac0ac5e1c43b1444bbdae6de15054443d501eadb83e1749a03bf4
|
File details
Details for the file pyheif-0.8.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
037fcfb4facb5160c6c874824b4fe4dab7855653a3114ed08c8273209d7e5cf5
|
|
| MD5 |
f599bb0dfb747ebf673252ee0d29ac6e
|
|
| BLAKE2b-256 |
2bb4947f2bc3800fcbead2e264b9ceaa41b6bb9eb85e7458847fa9aec6877f50
|
File details
Details for the file pyheif-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac63592bca147d74277664e5f46ae80fd721da1ab6650177d763201a43638f75
|
|
| MD5 |
6d19986eeb62bc4cc7213cdabbfc5dce
|
|
| BLAKE2b-256 |
0e20d4221a5e85f9ae4913ca265d4549e43279b1bd38e2ba4c5d847898b611f4
|
File details
Details for the file pyheif-0.8.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pyheif-0.8.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e4aa21e9bd92dbca7f3d281a4176611ccbcbb13990adcc74ccf4503498d2947
|
|
| MD5 |
ac9789678117130125ed026a84232580
|
|
| BLAKE2b-256 |
68361d15e207f0f2903c86c93ac03d1c33bcc62d8e546ade3836d0704a5ca47e
|