Skip to main content

Python 3.6+ interface to libheif library

Project description

pillow-heif

analysis build wheels test codecov style

PythonVersion impl pypi Downloads Downloads

Mac OS Windows Linux Alpine Linux

Library to work with HEIF files and an add-on for Pillow. Using the libheif via CFFI.

Here last release of 0.1 version: tag

Example of use as pillow plugin.

from PIL import Image, ImageSequence
from pillow_heif import register_heif_opener

register_heif_opener()

image = Image.open('images/input.heic')
for i, frame in enumerate(ImageSequence.Iterator(image)):
    rotated = frame.rotate(13)
    rotated.save(f'rotated_frame{i}.heic', quality=90)
exit(0)

Standalone example use

from PIL import Image
import pillow_heif

if pillow_heif.is_supported('input.heic'):
    heif_file = pillow_heif.open_heif('input.heic')
    for img in heif_file:  # you still can use it without iteration, like before.
        img.scale(1024, 768) # `libheif` does not provide much operations, that can be done on image, so just scaling it.
    heif_file.add_thumbnails([768, 512, 256]) # add three new thumbnail boxes.
    # default quality is probably ~77 in x265, set it a bit lower.
    heif_file.save('output.heic', quality=70, save_all=False) #save_all is True by default.
    exit(0)

More examples

Installation

From PyPi or Build from source

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
PyPy 3.7 v7.3 N/A N/A N/A
PyPy 3.8 v7.3 N/A N/A N/A
PyPy 3.9 v7.3 N/A N/A N/A

* i686, x86_64, aarch64 wheels.

Versions 0.2.X will be last to support Python 3.6

Base objects

More documentation will arrive soon, before 0.3.0 version...

The HeifImageFile object (as Pillow plugin)

The returned HeifImageFile by Pillow function Image.open has the following additional properties beside regular:

  • info dictionary keys:
    • main - boolean indication if this a main image in sequence.
    • brand - value from int enum HeifBrand.
    • exif - exif data or None.
    • metadata - is a list of dictionaries with type and data keys, excluding exif. May be empty.
    • icc_profile - contains data and present only when file has ICC color profile(prof or rICC).
    • nclx_profile - contains data and present only when file has NCLX color profile.

The HeifFile object

The returned HeifFile by function open_heif or from_pillow has the following properties:

  • size, has_alpha, mode, bit_depth, data, stride, info, etc - properties that points to main HeifImage
  • class supports len, iter and __getitem__:
    • len - returns number of top level images including main.
    • iter - returns a generator to iterate through all images, first image will be main.
    • __getitem__ - returns image by index, image with index=0 is main.
  • other useful class methods:
    • thumbnails_all - returns an iterator to access thumbnails for all images in file.
    • add_from_pillow - add image(s) from pillow :)
    • add_from_heif - add image(s) from another HeifFile.
    • save - saves HeifFile to fp that can be Path or BytesIO.

The HeifImage object

  • size - the size of the image as a (width, height) tuple of integers.
  • has_alpha - is a boolean indicating the presence of an alpha channel.
  • mode - the image mode, e.g. 'RGB' or 'RGBA'.
  • bit_depth - the number of bits in each component of a pixel.
  • data - the raw decoded file data, as bytes.
  • stride - the number of bytes in a row of decoded file data.
  • info - same dictionary as in HeifImageFile.info.
  • thumbnails - list of HeifThumbnail objects.

The HeifThumbnail object

  • size - the size of the image as a (width, height) tuple of integers.
  • has_alpha - is a boolean indicating the presence of an alpha channel.
  • mode - the image mode, e.g. 'RGB' or 'RGBA'.
  • bit_depth - the number of bits in each component of a pixel.
  • data - the raw decoded file data, as bytes.
  • stride - the number of bytes in a row of decoded file data.
  • img_index - index of image for which this thumbnail is.

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.2.2.tar.gz (7.4 MB view hashes)

Uploaded Source

Built Distributions

pillow_heif-0.2.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pillow_heif-0.2.2-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (8.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.2.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (11.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pillow_heif-0.2.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pillow_heif-0.2.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pillow_heif-0.2.2-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (8.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

pillow_heif-0.2.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (11.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pillow_heif-0.2.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (6.6 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pillow_heif-0.2.2-cp310-cp310-win_amd64.whl (5.5 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

pillow_heif-0.2.2-cp310-cp310-musllinux_1_1_x86_64.whl (13.9 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pillow_heif-0.2.2-cp310-cp310-musllinux_1_1_i686.whl (9.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pillow_heif-0.2.2-cp310-cp310-musllinux_1_1_aarch64.whl (12.5 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

pillow_heif-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pillow_heif-0.2.2-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (8.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

pillow_heif-0.2.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pillow_heif-0.2.2-cp310-cp310-macosx_12_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.10 macOS 12.0+ ARM64

pillow_heif-0.2.2-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.2.2-cp39-cp39-win_amd64.whl (5.5 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

pillow_heif-0.2.2-cp39-cp39-musllinux_1_1_x86_64.whl (13.9 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pillow_heif-0.2.2-cp39-cp39-musllinux_1_1_i686.whl (9.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pillow_heif-0.2.2-cp39-cp39-musllinux_1_1_aarch64.whl (12.5 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

pillow_heif-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pillow_heif-0.2.2-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (8.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

pillow_heif-0.2.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pillow_heif-0.2.2-cp39-cp39-macosx_12_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.9 macOS 12.0+ ARM64

pillow_heif-0.2.2-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.2.2-cp38-cp38-win_amd64.whl (5.5 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

pillow_heif-0.2.2-cp38-cp38-musllinux_1_1_x86_64.whl (13.9 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pillow_heif-0.2.2-cp38-cp38-musllinux_1_1_i686.whl (9.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

pillow_heif-0.2.2-cp38-cp38-musllinux_1_1_aarch64.whl (12.5 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

pillow_heif-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pillow_heif-0.2.2-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (8.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

pillow_heif-0.2.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pillow_heif-0.2.2-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.2.2-cp37-cp37m-win_amd64.whl (5.5 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

pillow_heif-0.2.2-cp37-cp37m-musllinux_1_1_x86_64.whl (13.9 MB view hashes)

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

pillow_heif-0.2.2-cp37-cp37m-musllinux_1_1_i686.whl (9.2 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

pillow_heif-0.2.2-cp37-cp37m-musllinux_1_1_aarch64.whl (12.5 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ ARM64

pillow_heif-0.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view hashes)

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

pillow_heif-0.2.2-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (8.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

pillow_heif-0.2.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.0 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.7m macOS 10.9+ x86-64

pillow_heif-0.2.2-cp36-cp36m-musllinux_1_1_x86_64.whl (13.9 MB view hashes)

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

pillow_heif-0.2.2-cp36-cp36m-musllinux_1_1_i686.whl (9.2 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ i686

pillow_heif-0.2.2-cp36-cp36m-musllinux_1_1_aarch64.whl (12.5 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ ARM64

pillow_heif-0.2.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view hashes)

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

pillow_heif-0.2.2-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (8.6 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686

pillow_heif-0.2.2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.0 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

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