Skip to main content

Python 3.7+ interface to libheif library

Project description

pillow_heif

static-analysis build published pypi

PythonVersion impl Downloads Downloads

A HEIF/HEIC add-on for Pillow using the libheif library via CFFI.

Binary wheels for Python 3.7-3.10. Linux(+Alpine)/macOS - x64/aarch64(+M1).

Version 0.1.4 was last to support Python 3.6 and still can be used.

Mostly based on David Poirier's pyheif. The idea for this plugin came from Christian Bianciotto's pyheif-pillow-opener. Many thanks!

Pull requests are greatly welcome.

Installation

(Recommended) You can install pillow_heif from PyPi:

pip install pillow_heif

or from GitHub:

pip install https://github.com/bigcat88/pillow_heif/archive/master.zip

Installation from source

Linux Ubuntu
sudo add-apt-repository ppa:strukturag/libheif
apt install libffi libheif-dev libde265-dev
pip install git+https://github.com/bigcat88/pillow_heif.git
MacOS
brew install libffi libheif
pip3 install git+https://github.com/bigcat88/pillow_heif.git

If on macOS it fails with installing from source, just try second time(helps me on M1 with Monterey):

pip3 install git+https://github.com/bigcat88/pillow_heif.git
Windows

With Visual Studio 2015+ C Compiler and SDK installed:

set INCLUDE=%INCLUDE%;X:\path\to\libheif\source
set LIB=%LIB%;X:\path\to\libheif\build
pip install git+https://github.com/bigcat88/pillow_heif.git

Example of use as opener

from PIL import Image
from pillow_heif import register_heif_opener

register_heif_opener()

image = Image.open('image.heic')
image.load()

Example of use as reader

from PIL import Image
import pillow_heif

heif_file = pillow_heif.read('ABC.HEIC')
image = Image.frombytes(
    heif_file.mode, 
    heif_file.size, 
    heif_file.data,
    'raw',
    heif_file.mode,
    heif_file.stride,
    )

The HeifFile object

The returned HeifFile has the following properties:

  • size - the size of the image as a (width, height) tuple of integers
  • brand - a list of heif_brand constants
  • has_alpha - (bool)presence of alpha channel
  • mode - the image mode, e.g. 'RGB' or 'RGBA'
  • bit_depth - the number of bits in each component of a pixel
  • metadata - a list of metadata dictionaries
  • color_profile - a color profile dictionary
  • data - the raw decoded file data, as bytes
  • stride - the number of bytes in a row of decoded file data

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

pillow_heif-0.1.5.tar.gz (30.5 MB view hashes)

Uploaded Source

Built Distributions

pillow_heif-0.1.5-cp310-cp310-musllinux_1_1_x86_64.whl (11.7 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pillow_heif-0.1.5-cp310-cp310-musllinux_1_1_aarch64.whl (11.1 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

pillow_heif-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pillow_heif-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pillow_heif-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pillow_heif-0.1.5-cp39-cp39-musllinux_1_1_x86_64.whl (11.7 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pillow_heif-0.1.5-cp39-cp39-musllinux_1_1_aarch64.whl (11.1 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

pillow_heif-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pillow_heif-0.1.5-cp39-cp39-macosx_11_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pillow_heif-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pillow_heif-0.1.5-cp38-cp38-musllinux_1_1_x86_64.whl (11.7 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pillow_heif-0.1.5-cp38-cp38-musllinux_1_1_aarch64.whl (11.1 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

pillow_heif-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pillow_heif-0.1.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.5 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pillow_heif-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pillow_heif-0.1.5-cp37-cp37m-musllinux_1_1_x86_64.whl (11.7 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

pillow_heif-0.1.5-cp37-cp37m-musllinux_1_1_aarch64.whl (11.1 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ ARM64

pillow_heif-0.1.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view hashes)

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

pillow_heif-0.1.5-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.5 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

pillow_heif-0.1.5-cp37-cp37m-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

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