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
- libwebp (tested with v1.0.3)
- Install libwebpmux and libwebpdemux components as well.
- Check out the Dockerfile for steps to build from source on Ubuntu.
- Python 3 (tested with v3.6)
- cffi
- Pillow
- numpy
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
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 -a v0.1.4 $ 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
setup.cfg
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.4.tar.gz
(10.4 kB
view hashes)
Built Distributions
webp-0.1.4-cp310-cp310-win_amd64.whl
(260.9 kB
view hashes)
webp-0.1.4-cp39-cp39-win_amd64.whl
(260.9 kB
view hashes)
webp-0.1.4-cp38-cp38-win_amd64.whl
(260.9 kB
view hashes)
webp-0.1.4-cp37-cp37m-win_amd64.whl
(260.9 kB
view hashes)
webp-0.1.4-cp36-cp36m-win_amd64.whl
(261.8 kB
view hashes)
Close
Hashes for webp-0.1.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a17f60508811dab3a4b2bb462fc1d9697a084cacd3d50699b854aec6221a208a |
|
MD5 | f56f5780d3354e7dff0b2862cb04169e |
|
BLAKE2b-256 | 69f1d85bedfd757cb7fbb8377310efed59231dbfccf573735be41c32ee912fed |
Close
Hashes for webp-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9445d190e32b830b71322007b9e89ef7e56595b6a4a450347f71ae37b50f2c2 |
|
MD5 | f7f195775dc4082792647cbdad5fdbcc |
|
BLAKE2b-256 | 4fa6903f2e0c5a98d786705f2fa00469e84a2c91cd19d56bb361191e9ac6e3b8 |
Close
Hashes for webp-0.1.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe9cbf52c1a80eefbdf5fab8ba5d442eaee409a06c2b32e2cfb0b08a792fe740 |
|
MD5 | 60704ae81adc197fd22f3189df879bfc |
|
BLAKE2b-256 | 63311c94e7a214cdfedcbbc845c276a9daa122ec80d26110925fdae9c52de8df |
Close
Hashes for webp-0.1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9b745f4730103d4f08a02c2b0317a2276e511a4aefc616cda209321d4337d3f |
|
MD5 | 8b69440434068f691bc4868a3812a5db |
|
BLAKE2b-256 | bc2053c15040efe4d4bdcc1b62a1e876fe85b2df02511b9c003a1aaaee30bd79 |
Close
Hashes for webp-0.1.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fcb42728510c75c796754a5ce46916664eb37124b7100f91cf8b6c23f073228 |
|
MD5 | 2689b0996105215234ad09bc611da62e |
|
BLAKE2b-256 | 0dfc7c4e54b84e069a24973aee8a15c2ded1e00a339c040f1eb45ece09a9c8a3 |
Close
Hashes for webp-0.1.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55f34ea37d012ff761843fc8f93909781d39660b8f17c09c8903d7cd1b9edf1f |
|
MD5 | cc0f7424f5deeb1cf418f2895dd7cf18 |
|
BLAKE2b-256 | 6f8b1133742f1cc209060aa88fd5b1fcb7650f2d320864ee59364e341e3d8699 |
Close
Hashes for webp-0.1.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61927b4d5f5b936c3026f61247f227b6c3f68b73db21d86b525fe81d72461d98 |
|
MD5 | 3e6ee79877c94cc92c445d308290c82d |
|
BLAKE2b-256 | 8b0bc9a418d0b37cf3c525e991fdbe8e50ba4f6851eac330f6c8a7f0867d717f |
Close
Hashes for webp-0.1.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5515f01fbde0f2ed5cc4e136d5f23bc6f7d17f18ee9f3d46d9719cf49ed3d822 |
|
MD5 | 5844cd6092cc1d9da110a33b5ecd4ecc |
|
BLAKE2b-256 | e272eb5327eb23a1f21bc7ab97bc0b9a4abc9a88015769d915b201038c3c9299 |
Close
Hashes for webp-0.1.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54c7bd36291ebc9584ccef97e0b62cedfbf080fcdd09a78aa1b5bbe40e407d78 |
|
MD5 | 92d21c07d689bc44b599212cae3b7889 |
|
BLAKE2b-256 | 4ca04c55e70bd2424e7ba560ac75126021cfb37c2da8833eac5720d59a94782a |
Close
Hashes for webp-0.1.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc69f9cbd1f9fc9993753fe296e2b936115109ea8e38191776bac50e490a1139 |
|
MD5 | 4becf528484b8d294a00c452ed0949c8 |
|
BLAKE2b-256 | 557338599c89ca13a8fdf543c7d66ea602680f5684bc3a2a77a8f7933a173c82 |