/pillow_heif

Python library to work with HEIF files and an add-on for Pillow.

Primary LanguagePythonGNU Lesser General Public License v2.1LGPL-2.1

pillow-heif

analysis build wheels test codecov style

PythonVersion impl pypi Downloads Downloads

Mac OS Windows Linux Alpine Linux

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. On windows currently only encoding of 8 bit images supported
  • EXIF, XMP, IPTC metadata support.
  • Support multiple images in one file, e.g HEIC files.
  • HEIF native thumbnails support.
  • Adding all this features to Pillow in one line of code as a plugin.
  • Includes AVIF(x264) decoder, can be turned off if not needed.

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)

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.

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
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