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:
$ pdm install -G:all
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.2.0.tar.gz
(18.8 kB
view hashes)
Built Distributions
webp-0.2.0-cp311-cp311-win_arm64.whl
(177.8 kB
view hashes)
webp-0.2.0-cp311-cp311-win_amd64.whl
(258.6 kB
view hashes)
webp-0.2.0-cp310-cp310-win_arm64.whl
(177.8 kB
view hashes)
webp-0.2.0-cp310-cp310-win_amd64.whl
(258.6 kB
view hashes)
webp-0.2.0-cp39-cp39-win_arm64.whl
(177.8 kB
view hashes)
webp-0.2.0-cp39-cp39-win_amd64.whl
(258.6 kB
view hashes)
webp-0.2.0-cp38-cp38-win_amd64.whl
(258.6 kB
view hashes)
Close
Hashes for webp-0.2.0-cp311-cp311-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cb0650f0d76e5f2bd621d8b685dd82ffa345cdf2a31386c20fc7ae23c8298d7 |
|
MD5 | 2b385f4fc2e61d429e0725b861c69afe |
|
BLAKE2b-256 | f39013c094c373534aa8907350dff4b68cefc2aeef4a78d25d52fb5a99cb44cf |
Close
Hashes for webp-0.2.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 009c44497d278229c352ab2d3418e850c28bb1495206bbd6788dfda8268716ee |
|
MD5 | d679b9ff4018f04af58a11731c6326a1 |
|
BLAKE2b-256 | c3989e79d46d6098a86706a8f6675f45ff1258a040a9460097a774d32adb7963 |
Close
Hashes for webp-0.2.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7416899365090ec8eb0672d274137e99c2e7cec81478b40eab9f033f3741674 |
|
MD5 | aaf5b3c0411fc84aa676d03ac1b332e3 |
|
BLAKE2b-256 | 04654c26b833b7a0caf80027c927a10c50a69ef1c2b2fe41f9106c8e820b03ec |
Close
Hashes for webp-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b9f6210194da70a4b43957bb2f3aa3f575c1c1956371b90c8390fd1647e02f5 |
|
MD5 | b64f58373483fe60ca3089c0a0ad317d |
|
BLAKE2b-256 | 77d42449b2e7203ad30e3bfa2336b2c85008df1c07f900931ddd9927aad12349 |
Close
Hashes for webp-0.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ab703f60beb08fa87465246e6978fbed882d7fa43cb593b7e2fd35d31906bf7 |
|
MD5 | f7e718a7ebfe81e7bfac593edf8fd664 |
|
BLAKE2b-256 | de626f6a5f6f53d61385d788ccb8c172166cceef38ed046dd22b79d1f98cef7e |
Close
Hashes for webp-0.2.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 251ac33eec030bf8693b4bee1fffc5126a4476117861b523b19ed7f95cbb63f9 |
|
MD5 | 6371438a7d0b6b93f1a52094831f29c6 |
|
BLAKE2b-256 | b9c2867868fbe858deccd677a7f6c2c0788de8700cf33db1f118f08392cf7598 |
Close
Hashes for webp-0.2.0-cp310-cp310-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b0650e066dcfd6c229d9f6b7ec7556a02d776f9eeb0bd5a8140e840c41ca8a7 |
|
MD5 | f4ff650fd7ec43567aa6441ffb132be3 |
|
BLAKE2b-256 | b32e018ff690586ee7a03ba0be3b78114a4e60c219b0ee48198c83bc0e3e60ee |
Close
Hashes for webp-0.2.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8b07d0d105f4647f502866a915360e5752c67470d2f0effe797e9df0241dfbf |
|
MD5 | 16dac8d7bc8e8b87949dc2fb465018cc |
|
BLAKE2b-256 | 9edb0436879996a6135e2247053a599c89fca1018e83e541acaef9765b3b3808 |
Close
Hashes for webp-0.2.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5f9871c7e3e1e3d303bf20814f8af2c54a75335643bb3662210024902b9f94e |
|
MD5 | 012f19b77a7f60ba8df4f1233f5bc8bc |
|
BLAKE2b-256 | 02b2d758ee7aec2092f133db7086b7a0cc95a2bfa8179c6e3cf4c54220bdc0db |
Close
Hashes for webp-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32ca3b8c13a7ce2c83b12423d219e6a3a43c177df21a3e14ebe05856b5904512 |
|
MD5 | 6be09d94412dacf3d654f5e599266b74 |
|
BLAKE2b-256 | 9c4d7fc94e7b321de9988038df0b739116ddcf596a5c6da7853d7a09b56ba348 |
Close
Hashes for webp-0.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb84edd4282aa2359f76fcdd8a4a03aaa5615340eb467329a9925b53bcc0f0fa |
|
MD5 | beeb592944592efb584984ed43a25b21 |
|
BLAKE2b-256 | e1cf129e650cde973cc5d37d82505eeb8b3f06b940f0a27785ba60ac4e1e67e4 |
Close
Hashes for webp-0.2.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e7861ae6c760eb61bb42689b14c41cc88393dedfa24f1786cc6c82273283adb |
|
MD5 | 1d075615b6fbdd766918e41765028339 |
|
BLAKE2b-256 | 6ff1c75cfb94df3d4ba8c4941810ec961f80feda6d32ecb4d41153ad7805c4ae |
Close
Hashes for webp-0.2.0-cp39-cp39-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c472a9afb964f2113f42b163452964de95f638cadcfa1c22152a0cc86232b4a |
|
MD5 | be5dd52c179efe2e487585b5434925c9 |
|
BLAKE2b-256 | c25a39d36703e2a9b16f08cebfec4e4b4c44395618b3413fce3c12b9c3facd87 |
Close
Hashes for webp-0.2.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d28e78bb6b6644f7d8f6fe7d11a853552a0922693c5b1830677d649ca8aaefb |
|
MD5 | 69c7f64a1be47561cda075d212c07b02 |
|
BLAKE2b-256 | 7b07cdcfb5b50c03ba0353571f4144d9c1008ec8347052a76df55eca16ca6c4d |
Close
Hashes for webp-0.2.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5df2c725b15d1c38b47ceedc3693857923b5708d2b353acef92071a74a96245 |
|
MD5 | 629378f977a98e2fdd99444f865a963c |
|
BLAKE2b-256 | 6adfd188dc97d751dc3bdc291c10da9d7fbd752969c37f86f5abca0290ff96c9 |
Close
Hashes for webp-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10c9e336364f9fcf09dfa6423903956d9268bce7dd63735c15b16ef00c3be141 |
|
MD5 | a7f5cb833dac6e78fad1468d42d31530 |
|
BLAKE2b-256 | 128fab890fe0e2aa605612305c5890c4fc288a067dc59c9f7c6f0772eaeb5790 |
Close
Hashes for webp-0.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 542374518dd2208798cdaf831e77f4eddc887ba5a709851436074788c9df4753 |
|
MD5 | 9319fdecd87ec190b909e5a804b19333 |
|
BLAKE2b-256 | 4cd39f583de1ecd76f356d23bc14b3d69cd8bc22f8750e7704957e7e54f5d000 |
Close
Hashes for webp-0.2.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a690311c22a4a199d11426d19cf5918db2992e6fa2ebe2e9761cf384cce1f772 |
|
MD5 | 20ee599207281e5912d4b00884cfc24c |
|
BLAKE2b-256 | 32a7dba01a5746156905815779ac5f04eb9b978f259c7cc1bd142553149e663d |
Close
Hashes for webp-0.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5563cc7fe8fc4c6a0fc04420ab8638fa0dbc32a11aafb82afc7e335b84ed267 |
|
MD5 | d097fb73c23f471656e0832b967cf16d |
|
BLAKE2b-256 | 865b8ace70543341aa4fc535df01c30e19e30e9282d4b338338b07094e27a138 |
Close
Hashes for webp-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8700e1986be75d3ed9c6ba24a27e7d3f7a82101caeb5a88da3cea6c40e05df48 |
|
MD5 | 5005bfb04f4d877c11c7feaa24b1cacb |
|
BLAKE2b-256 | 7b6fd6347b1b8c46f90111942687d9f8230bf6721866bc1c7764922c7db2a761 |
Close
Hashes for webp-0.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4adac52d140ea0f0e282a2d97b7baa38e5dfe977b29073d00416706d8ebfe3f |
|
MD5 | 012713059206e515d8006e116c5196a3 |
|
BLAKE2b-256 | 58f6986fe2556c7b65dc63691954e9f9cb419ae129759197c2e49b2cf75fe24d |
Close
Hashes for webp-0.2.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eebf4a2453743995117a79fd6bd6ab4f4ea74fd8df3bd7502973cc38a92944d4 |
|
MD5 | 5bc17ef54a67e86ca6d2eb28db81f301 |
|
BLAKE2b-256 | fd58c0ea14c300f7d162cd7cb523766f9dbcfebfc55df5148069fa5bd21591d3 |