Skip to main content

Python bindings for WebP

Project description

WebP Python bindings

Build status License PyPI GitHub

Installation

pip install webp

On Windows you may encounter the following error during installation:

conans.errors.ConanException: 'settings.compiler' value not defined

This means that you need to install a C compiler and configure Conan so that it knows which compiler to use. See https://github.com/anibali/pywebp/issues/20 for more details.

Requirements

  • Python 3.8+

Usage

import webp

Simple API

# Save an image
webp.save_image(img, 'image.webp', quality=80)

# Load an image
img = webp.load_image('image.webp', 'RGBA')

# Save an animation
webp.save_images(imgs, 'anim.webp', fps=10, lossless=True)

# Load an animation
imgs = webp.load_images('anim.webp', 'RGB', fps=10)

If you prefer working with numpy arrays, use the functions imwrite, imread, mimwrite, and mimread instead.

Advanced API

# Encode a PIL image to WebP in memory, with encoder hints
pic = webp.WebPPicture.from_pil(img)
config = WebPConfig.new(preset=webp.WebPPreset.PHOTO, quality=70)
buf = pic.encode(config).buffer()

# Read a WebP file and decode to a BGR numpy array
with open('image.webp', 'rb') as f:
  webp_data = webp.WebPData.from_buffer(f.read())
  arr = webp_data.decode(color_mode=WebPColorMode.BGR)

# Save an animation
enc = webp.WebPAnimEncoder.new(width, height)
timestamp_ms = 0
for img in imgs:
  pic = webp.WebPPicture.from_pil(img)
  enc.encode_frame(pic, timestamp_ms)
  timestamp_ms += 250
anim_data = enc.assemble(timestamp_ms)
with open('anim.webp', 'wb') as f:
  f.write(anim_data.buffer())

# Load an animation
with open('anim.webp', 'rb') as f:
  webp_data = webp.WebPData.from_buffer(f.read())
  dec = webp.WebPAnimDecoder.new(webp_data)
  for arr, timestamp_ms in dec.frames():
    # `arr` contains decoded pixels for the frame
    # `timestamp_ms` contains the _end_ time of the frame
    pass

Features

  • Picture encoding/decoding
  • Animation encoding/decoding
  • Automatic memory management
  • Simple API for working with PIL.Image objects

Not implemented

  • Encoding/decoding still images in YUV color mode
  • Advanced muxing/demuxing (color profiles, etc.)
  • Expose all useful fields

Developer notes

Setting up

  1. Install mamba and conda-lock. The easiest way to do this is by installing Mambaforge and then running mamba install conda-lock.
  2. Create and activate the Conda environment:
    $ conda-lock install -n webp
    $ mamba activate webp
    
  3. Install PyPI dependencies:
    $ poetry install
    

Running tests

$ pytest tests/

Cutting a new release

  1. Ensure that tests are passing and everything is ready for release.
  2. Create and push a Git tag:
    $ git tag v0.1.6
    $ git push --tags
    
  3. Download the artifacts from GitHub Actions, which will include the source distribution tarball and binary wheels.
  4. Create a new release on GitHub from the tagged commit and upload the packages as attachments to the release.
  5. Also upload the packages to PyPI using Twine:
    $ twine upload webp-*.tar.gz webp-*.whl
    
  6. Bump the version number in pyproject.toml and create a commit, signalling the start of development on the next version.

These files should also be added to a GitHub release.

Known issues

  • An animation where all frames are identical will "collapse" in on itself, resulting in a single frame. Unfortunately, WebP seems to discard timestamp information in this case, which breaks webp.load_images when the FPS is specified.
  • There are currently no 32-bit binaries of libwebp uploaded to Conan Center. If you are running 32-bit Python, libwebp will be built from source.

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

webp-0.1.6.tar.gz (13.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

webp-0.1.6-cp311-cp311-win_amd64.whl (261.5 kB view details)

Uploaded CPython 3.11Windows x86-64

webp-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (425.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

webp-0.1.6-cp311-cp311-macosx_11_0_x86_64.whl (349.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ x86-64

webp-0.1.6-cp310-cp310-win_amd64.whl (261.5 kB view details)

Uploaded CPython 3.10Windows x86-64

webp-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (425.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

webp-0.1.6-cp310-cp310-macosx_11_0_x86_64.whl (349.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

webp-0.1.6-cp39-cp39-win_amd64.whl (261.5 kB view details)

Uploaded CPython 3.9Windows x86-64

webp-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (425.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

webp-0.1.6-cp39-cp39-macosx_11_0_x86_64.whl (349.6 kB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

webp-0.1.6-cp38-cp38-win_amd64.whl (261.5 kB view details)

Uploaded CPython 3.8Windows x86-64

webp-0.1.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (425.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

webp-0.1.6-cp38-cp38-macosx_11_0_x86_64.whl (349.6 kB view details)

Uploaded CPython 3.8macOS 11.0+ x86-64

File details

Details for the file webp-0.1.6.tar.gz.

File metadata

  • Download URL: webp-0.1.6.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for webp-0.1.6.tar.gz
Algorithm Hash digest
SHA256 3af22162a72fd9139ba6548eef7bf434d7109f6eb0e449a08dea75f6c373243c
MD5 44857014e8f3629919f66b253dc57c64
BLAKE2b-256 656df7401c6284beb5f5736ec23967b6b1e3d7cd64b987e1b03225b5830af063

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: webp-0.1.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 261.5 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for webp-0.1.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c50d56c4c71e0e02e033ef1562a143cdd2b85a2a4647d7905119bfe0e8287244
MD5 932d949d5aaf4ac9a298cb192d396163
BLAKE2b-256 e99d9d5f07482b0a215d9fe90ffd782bffd30a4a495a07ab49e7fb1ca02370fa

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for webp-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 413cae9171460039f9d9ded9eb30cca1ac80096ec3a2b83b18ce8040e043f605
MD5 785c05d3b5996f36d0d98882e79b49fe
BLAKE2b-256 c3a758f7dc70eefa07a004f28ed5a6ecf70e22c75d20b968b9bd2a065def4e79

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp311-cp311-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for webp-0.1.6-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 9f476e9458b5c97d149d96705a0e5a3bf2acb30ffeba9657ba48bb3946058a53
MD5 4250e29df8f243fa019c4e8615e56df6
BLAKE2b-256 159bd408e05d680b4a2b951be4287c9853b02131747c085ee9d4950a09972bd4

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: webp-0.1.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 261.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for webp-0.1.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 53cbafae866149e6e730d29913af8227de4b4cd871f3357eb998369b1d81e9a1
MD5 89d12018a85b18609797bbb07f3001f2
BLAKE2b-256 a4005af37ad8860f7cfce05511c9462fe8021c5b9aba5a1edc23f9b4ba386c64

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for webp-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 316051cf83f7a9444fc89834fdeca098f58772ee73b3523dcfef6f15e5fd30f0
MD5 851115380a5e5c9578d2cad255aa041f
BLAKE2b-256 fc6f47c612ab8effb353f191f29bdb1dda7bc5056baddbde154bdfe5398ee6d7

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for webp-0.1.6-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0d5c79990d1b97c6fe695323daffbe3412e37332b4759e8b5e4b94def8ca06d5
MD5 88b6a6ca1f19605dbf3f9cdf54ec6055
BLAKE2b-256 8fe027981ae176858b96e52fefd8ac6e6503514be5f61c024a5e55e01b3c65ad

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: webp-0.1.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 261.5 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for webp-0.1.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 34730ad218c04b95aac939fc89a55711d52f8512c53265c43cccbcb97d826398
MD5 909860df46c314635ba86c87b1d66eca
BLAKE2b-256 95c21030268c20b15a8dde080d223317c50fe5703d619334cb702487d1ff8ed0

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for webp-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc70b16c9f1efdad23831ac20e0e76838a677d1a589bcf040fc1cc4dbc3ae68c
MD5 6618f12703eeb7ace7e16cae860d05c2
BLAKE2b-256 70acaf4fcc4e71db0ae85991f15eee7b37d2b0170f8bd8a5c53f9d5453efe19a

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: webp-0.1.6-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 349.6 kB
  • Tags: CPython 3.9, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for webp-0.1.6-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 2c667187aebc11a8ca3e4f0283d70217c0f43e6bcfb8c490d146aa516e261e82
MD5 99291cd7472b3547cbe2220647d9241d
BLAKE2b-256 e46f199ad18b7de49af0a2e184524818bc09ca3b200866d052aa98a6df7026d1

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: webp-0.1.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 261.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for webp-0.1.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 bcf63e82624139dec6bc67754e5daf25aebfe6f04c2c49884cb97185fad557c3
MD5 5c6f00762651bd47b9adcd26a469e095
BLAKE2b-256 63f15fe3ae15d9f03a89fc0ee7cd1bba674add707e7c4539ec384d23a43dc30c

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for webp-0.1.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2956cbb8fe493f3aba4f6dace817aa1687849b3ea8f99826955fcd5525bf5c96
MD5 b94fab6e057f6f1c31a362b81713bbd3
BLAKE2b-256 a77e1675f4e990479bdd2ced896f11d8a25b99c80944da6bd0c64b852b28bdbf

See more details on using hashes here.

File details

Details for the file webp-0.1.6-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: webp-0.1.6-cp38-cp38-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 349.6 kB
  • Tags: CPython 3.8, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for webp-0.1.6-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 b85293804d99969ef35e4a5dcdadec071a84e8b6d87fbaaf143a4e4b5a6fe90a
MD5 fa23e29e3be67cfb057f4870eddd2e39
BLAKE2b-256 e6ff53722b010719ef73e986fb80b3ba457f8d76a259be4586e3b1412c0d2a77

See more details on using hashes here.

Supported by

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