Python bindings for WebP
Project description
WebP Python bindings
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
- Install
mamba
andconda-lock
. The easiest way to do this is by installing Mambaforge and then runningmamba install conda-lock
. - Create and activate the Conda environment:
$ conda-lock install -n webp $ mamba activate webp
- Install PyPI dependencies:
$ poetry install
Running tests
$ pytest tests/
Cutting a new release
- Ensure that tests are passing and everything is ready for release.
- Create and push a Git tag:
$ git tag v0.1.6 $ git push --tags
- Download the artifacts from GitHub Actions, which will include the source distribution tarball and binary wheels.
- Create a new release on GitHub from the tagged commit and upload the packages as attachments to the release.
- Also upload the packages to PyPI using Twine:
$ twine upload webp-*.tar.gz webp-*.whl
- 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
Release history Release notifications | RSS feed
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 hashes)
Built Distributions
webp-0.1.6-cp311-cp311-win_amd64.whl
(261.5 kB
view hashes)
webp-0.1.6-cp310-cp310-win_amd64.whl
(261.5 kB
view hashes)
webp-0.1.6-cp39-cp39-win_amd64.whl
(261.5 kB
view hashes)
webp-0.1.6-cp38-cp38-win_amd64.whl
(261.5 kB
view hashes)
Close
Hashes for webp-0.1.6-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50d56c4c71e0e02e033ef1562a143cdd2b85a2a4647d7905119bfe0e8287244 |
|
MD5 | 932d949d5aaf4ac9a298cb192d396163 |
|
BLAKE2b-256 | e99d9d5f07482b0a215d9fe90ffd782bffd30a4a495a07ab49e7fb1ca02370fa |
Close
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 |
Close
Hashes for webp-0.1.6-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f476e9458b5c97d149d96705a0e5a3bf2acb30ffeba9657ba48bb3946058a53 |
|
MD5 | 4250e29df8f243fa019c4e8615e56df6 |
|
BLAKE2b-256 | 159bd408e05d680b4a2b951be4287c9853b02131747c085ee9d4950a09972bd4 |
Close
Hashes for webp-0.1.6-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53cbafae866149e6e730d29913af8227de4b4cd871f3357eb998369b1d81e9a1 |
|
MD5 | 89d12018a85b18609797bbb07f3001f2 |
|
BLAKE2b-256 | a4005af37ad8860f7cfce05511c9462fe8021c5b9aba5a1edc23f9b4ba386c64 |
Close
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 |
Close
Hashes for webp-0.1.6-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d5c79990d1b97c6fe695323daffbe3412e37332b4759e8b5e4b94def8ca06d5 |
|
MD5 | 88b6a6ca1f19605dbf3f9cdf54ec6055 |
|
BLAKE2b-256 | 8fe027981ae176858b96e52fefd8ac6e6503514be5f61c024a5e55e01b3c65ad |
Close
Hashes for webp-0.1.6-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34730ad218c04b95aac939fc89a55711d52f8512c53265c43cccbcb97d826398 |
|
MD5 | 909860df46c314635ba86c87b1d66eca |
|
BLAKE2b-256 | 95c21030268c20b15a8dde080d223317c50fe5703d619334cb702487d1ff8ed0 |
Close
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 |
Close
Hashes for webp-0.1.6-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c667187aebc11a8ca3e4f0283d70217c0f43e6bcfb8c490d146aa516e261e82 |
|
MD5 | 99291cd7472b3547cbe2220647d9241d |
|
BLAKE2b-256 | e46f199ad18b7de49af0a2e184524818bc09ca3b200866d052aa98a6df7026d1 |
Close
Hashes for webp-0.1.6-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcf63e82624139dec6bc67754e5daf25aebfe6f04c2c49884cb97185fad557c3 |
|
MD5 | 5c6f00762651bd47b9adcd26a469e095 |
|
BLAKE2b-256 | 63f15fe3ae15d9f03a89fc0ee7cd1bba674add707e7c4539ec384d23a43dc30c |
Close
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 |
Close
Hashes for webp-0.1.6-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b85293804d99969ef35e4a5dcdadec071a84e8b6d87fbaaf143a4e4b5a6fe90a |
|
MD5 | fa23e29e3be67cfb057f4870eddd2e39 |
|
BLAKE2b-256 | e6ff53722b010719ef73e986fb80b3ba457f8d76a259be4586e3b1412c0d2a77 |