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.7+
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 -a v0.1.5 $ 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.5.tar.gz
(13.1 kB
view hashes)
Built Distributions
webp-0.1.5-cp311-cp311-win_amd64.whl
(266.6 kB
view hashes)
webp-0.1.5-cp310-cp310-win_amd64.whl
(266.6 kB
view hashes)
webp-0.1.5-cp39-cp39-win_amd64.whl
(266.6 kB
view hashes)
webp-0.1.5-cp38-cp38-win_amd64.whl
(266.6 kB
view hashes)
webp-0.1.5-cp37-cp37m-win_amd64.whl
(266.6 kB
view hashes)
Close
Hashes for webp-0.1.5-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd05b135de0cc66ae19b3a6ca2d5e5806a4981aba2a4b3527290e3992ef4d621 |
|
MD5 | 803a6dc162821883ea5d9fc6a772ad1a |
|
BLAKE2b-256 | c6650dffd3b4a25c12334217ece61899bcf1ad698239b125f2fbb7ead9cfdf5a |
Close
Hashes for webp-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d9a542ed895df52d7f084f6df2468ae1c04f49bab2d72d8282f5938008d87bf |
|
MD5 | 01cb1b47f6438e8d5efdf893f6442108 |
|
BLAKE2b-256 | 42ccf46e30e6696927fe6c88e7f1b985bb207c5958c625405de851cf4ad20d59 |
Close
Hashes for webp-0.1.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 043731e7c22718fe27fc5049bf54734b94f7828579df81c2bf7f83395fe88fe0 |
|
MD5 | 1327d971577a576a794a3fe131dcf4c2 |
|
BLAKE2b-256 | e4313d32a2c51a60f1e9f32f1d365972bad4674aa886119dfd867c693bf2f561 |
Close
Hashes for webp-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25c78544a092a8fe74f9bb41d167d4338d2a9abf198e0f83752f847b76aa1b4c |
|
MD5 | 3306fc9ab81bcfdaa811bfd61f6c40e6 |
|
BLAKE2b-256 | 6f17836899ddf27492797a9d6dd36edf2c98540977ad387ecee7cc18a75d91b6 |
Close
Hashes for webp-0.1.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf1c9df4dbe81039e73b7f48ef3a9653c4928f8e58fe5ffef12d43299b5a63c8 |
|
MD5 | ecc8d900f1ec19e105a0204add033418 |
|
BLAKE2b-256 | 2e6c67d131d008c244059c91d1716ae96fd9a8a69bdd5163f8b2c5279a4f343a |
Close
Hashes for webp-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b9556a876cc63b8ac116c2c710354bb7a8b304a5275481201a0af54fa163cb0 |
|
MD5 | dea316510c6ce6232c6495c4e95c0230 |
|
BLAKE2b-256 | de8cef92f7ef0ddb7ff3365aae175efd2df7224fe62d2ebe56a3dfdddfa14e50 |
Close
Hashes for webp-0.1.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b95e3b22acb6249bb715739464efda5f6bbdd4fcc7fc298c580b0c73853f6972 |
|
MD5 | 66195e58372de2c27a1c04983d7a69ad |
|
BLAKE2b-256 | 4575ab68dc82a46a89f3b09c9f51360f25d942ed8862623c8b975b4bc4bd0206 |
Close
Hashes for webp-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d428d45e4ebfc0aa675422fdd8d326808dfbc500228d8b55228f809575338514 |
|
MD5 | fde996965b72fa8533a2b40acb2fd21c |
|
BLAKE2b-256 | 15d693e6f474ff4236e28233a208b5aa478436d27a73ffc02e547dfc81c25bd5 |
Close
Hashes for webp-0.1.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26b1e595b3af6440192f0dc55ae518b5d95ed10062a757ca4f77a5b9a01008cb |
|
MD5 | 7483751969a8d907b6384bbddd486111 |
|
BLAKE2b-256 | 4b546960b0edb8a51753b8d79c656ed30d985a7bfaf2d5ab7faae6ef7d0e9ab0 |
Close
Hashes for webp-0.1.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 356cc43d32b24751c911c83f4f6070319c31773a26f1eea904916ad32659f148 |
|
MD5 | e8766835b6c594f7b2a5c7507db2eb6e |
|
BLAKE2b-256 | 563a7f6128915e05ec0677f8279f41dd27f4226752231e9805c332789077302d |