Skip to main content

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.Path path object
  • A Python bytes or bytearray object 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 integers
  • data - the raw decoded file data, as bytes
  • metadata - a list of metadata dictionaries
  • color_profile - a color profile dictionary
  • stride - the number of bytes in a row of decoded file data
  • bit_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 - the HeifTopLevelImage object of the primary image in the file.
  • top_level_images - a list of all HeifTopLevelImage objects in the file.

The HeifTopLevelImage object

The HeifTopLevelImage has the following properties:

  • id - the id of the image
  • image - the UndecodedHeifImage or HeifImage object of the image
  • is_primary - is this the primary image in the container
  • depth_image - the HeifDepthImage if there is one
  • auxiliary_images - a list of HeifAuxiliaryImage objects

The HeifDepthImage object

The HeifDepthImage has the following properties:

  • id - the id of the image
  • image - the UndecodedHeifImage or HeifImage object of the image

The HeifAuxiliaryImage object

The HeifAuxiliaryImage has the following properties:

  • id - the id of the image
  • image - the UndecodedHeifImage or HeifImage object of the image
  • type - a string indicating the type of auxiliary image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyheif-0.8.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distributions

pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.2 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.3 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.2 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.3 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pyheif-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pyheif-0.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

pyheif-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyheif-0.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pyheif-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyheif-0.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pyheif-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyheif-0.8.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pyheif-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyheif-0.8.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pyheif-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyheif-0.8.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

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

Hashes for pyheif-0.8.0.tar.gz
Algorithm Hash digest
SHA256 e9b4c11ebad482fc25a0804ce295b44b660cbf7829a228f56b071f325f9e0de4
MD5 5e84d911b7733d426170742b03d994c2
BLAKE2b-256 ec11d63f215d8c9c416409e2d665bf7594a8886780629296b4f0d35857561c9b

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef3255c5dd9062f38fea0f4cb41f3192616307252db448a2064f8bce31640112
MD5 0e20a7f4b22e6bb93580bb1d6a4f7eba
BLAKE2b-256 15b56cbe1e0bcd0db171e57a838fbf611d937ce120b87a045b6d4a868d85f394

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c9f1c8e3158b98fc82b3833e7358f6ca0ef9d50fa93d20993925917e9189bbc6
MD5 34e7088e2a39f13cfe98b4d8bea19f2b
BLAKE2b-256 35175a5a70da5b6dd52937e38259e65180414e4c5625717b139a6f7aa30a79a5

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b896eebf440ea826893a253c8f8a5bbd245f96a1613858d7c4ec310420ab9cec
MD5 b2c037d815b40f5a788d9ab6e741c341
BLAKE2b-256 4c0dcee50b45e7360226e6c66f9b65fbb3a354ab7a35dc54e335d1cae9f03dcc

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 39214792559eab90814f9551540156550619fc6f8f0d794091488563577da5ca
MD5 247ed0ccba9d0e459b70cddcab41b775
BLAKE2b-256 8d97a180a87119f81f06d032a0530f4636e1c1e75d9589c8c6b915d80cb0743f

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f98f4b1d37705418d77ef42a8ebf95b510bb3e0a9a2d9f0824f6eeb751c9e7f6
MD5 b77316811a749bf8eae784e76f27c94f
BLAKE2b-256 87c41d0e82766657b3839993ffe411807a08623ff9affd7275533afea3cb377e

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ac5ec62a90c4f9f96125aaebd6ac994b95895ace4427ecf34752951e1d34be96
MD5 3e529a7fedda111678f5043cfe11795e
BLAKE2b-256 fc4907d1c047e52fd4de1474759e202b2fd7ac99e945db0ce149af2f85be7625

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4c8723ab28ca9f42e0f25a29008673654e062edb95b26dbfa3e397e6cc3d56b8
MD5 7069a8146ed5b56b2a1013a561b614c4
BLAKE2b-256 6fa92514a4d53ed5712bdda42281d0b3b0f652ccd35ba08b66039510592cf67e

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 01c94cc524446d6e23a2726d4cec94c764b277466cbeca4d95e083390b09ad34
MD5 9397567376aa90ecb82a8b5a244c6218
BLAKE2b-256 62e752450ce4cf5e682ea8950f86725dffad461ca8b24c9215ac76d61e2d8392

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e93ff599eba671718e9dcab2dcd4efdbcbdbe4bcd31bd9477026e2ffc39125b2
MD5 0735612d512f4fc15530e5d4a4c43b50
BLAKE2b-256 d29aec37ceaf6b93a23c33c6080a7ac2570148d0a51fc4db733dc2ea735526de

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6a9df316c695c7a4588633486c5f93508474653488dbcb8c968dc0c611875106
MD5 d8f1fc8d85b5f95faf27fb158b896df1
BLAKE2b-256 529840d97d38454f6708db7b819b8c206e206e4730183860b3a3be56fa44cdab

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f6e08cdd85f638e134cbd94006631d8e5263002a3f8c4f44b1f94626fb0cf4f3
MD5 06f47bc22bb39de04eec44029440c638
BLAKE2b-256 1142b0fac6f16c96e54039bc66578aa559a06d0c24c413e9f061dc2d1ac1637e

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 adba452e061b4b1edf57ad561daf69f3e67de4be42088885685ef4e6a8dd9baf
MD5 cfcc385a95654cb3833a7b84ff347ddd
BLAKE2b-256 25ed108eabdcbd8a12ac31b4979dd9a9bfd8342590db27037ecba3ce5a773276

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 272d08f3308dcac1ad12b100f0d433f28e4f6e2aef0c28feee1d4b2bbf7e8f81
MD5 7260c4dec1f0f16e11aca5f4028785c0
BLAKE2b-256 391b1519742ac0ac5e1c43b1444bbdae6de15054443d501eadb83e1749a03bf4

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 037fcfb4facb5160c6c874824b4fe4dab7855653a3114ed08c8273209d7e5cf5
MD5 f599bb0dfb747ebf673252ee0d29ac6e
BLAKE2b-256 2bb4947f2bc3800fcbead2e264b9ceaa41b6bb9eb85e7458847fa9aec6877f50

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ac63592bca147d74277664e5f46ae80fd721da1ab6650177d763201a43638f75
MD5 6d19986eeb62bc4cc7213cdabbfc5dce
BLAKE2b-256 0e20d4221a5e85f9ae4913ca265d4549e43279b1bd38e2ba4c5d847898b611f4

See more details on using hashes here.

File details

Details for the file pyheif-0.8.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyheif-0.8.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4e4aa21e9bd92dbca7f3d281a4176611ccbcbb13990adcc74ccf4503498d2947
MD5 ac9789678117130125ed026a84232580
BLAKE2b-256 68361d15e207f0f2903c86c93ac03d1c33bcc62d8e546ade3836d0704a5ca47e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page