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.1.8.tar.gz
(17.9 kB
view hashes)
Built Distributions
webp-0.1.8-cp311-cp311-win_amd64.whl
(258.8 kB
view hashes)
webp-0.1.8-cp310-cp310-win_amd64.whl
(258.8 kB
view hashes)
webp-0.1.8-cp39-cp39-win_amd64.whl
(258.8 kB
view hashes)
webp-0.1.8-cp38-cp38-win_amd64.whl
(258.8 kB
view hashes)
Close
Hashes for webp-0.1.8-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bd219022d61cd1957e8fd5a6c32ad2474c7c5e50efcd1ecb34096805ff60333 |
|
MD5 | 3d7b0ce6bf1b79cd77f4c69e81845d86 |
|
BLAKE2b-256 | ccdf68b8fbd9a6f40fa9a6097916cebdae31d26259761701e9fe4536ae7f6d44 |
Close
Hashes for webp-0.1.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69fb97ce71fb071881041145dfbd62a4171a8a13fc7ad0753e4b2bda84109bac |
|
MD5 | dbfbb02d1521822fa93fa8f23deb1300 |
|
BLAKE2b-256 | 4a710db7ee0acf3d85dedede008dcdf199902d2043339b3664dcf3c5b86b68dc |
Close
Hashes for webp-0.1.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 310d2c03b4ceff9bde6729f7ee621db9192c8b61fb0c5988a225bc7ef7cfba59 |
|
MD5 | 3de82557626c934fbacd922f65ac23a7 |
|
BLAKE2b-256 | 4eedbe27d8cf43e15a65fe90decdce14e163b5b339dd8e1cb57b0b4362b30420 |
Close
Hashes for webp-0.1.8-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3232c9552f3036331bf5079fc8173bab84f47e575bce2ac5b552e2596c50dc37 |
|
MD5 | 47ade0648e9993b154ec4a5e38a8b602 |
|
BLAKE2b-256 | 99bd7e7ea45baf19fc668913daf6515eac4da2c4547009c9d7cdae1867453c6e |
Close
Hashes for webp-0.1.8-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33f91f705febe7b150c7c0e163beaa447018f61ac95c57f56af19c694d0679f2 |
|
MD5 | 3d5f5e5c50f1fa56c65fd12c2793c144 |
|
BLAKE2b-256 | 61d752424e09ec5568868cf20b0f20b4189e99a92d7f82591eb2f934533215b6 |
Close
Hashes for webp-0.1.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c468401c7241e885717d03de5b46539a530e962a1a12c596609c213267121cc |
|
MD5 | 80118c325ad398b168a5c7111015f437 |
|
BLAKE2b-256 | 6c317aa0976e8f592ce2667f80bfb76ae80ad0d039f100075f783403bedf324e |
Close
Hashes for webp-0.1.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df2378017bddf72f8ca6b5ab9adce0de7cf50dcc4fd310325e62e90a6bacb5d2 |
|
MD5 | 46c35d734326df7fa6743d0be4669858 |
|
BLAKE2b-256 | d96ad4a04d99c0a6147cc3e78e1de9217b1238363ab3bf8d0421d9f18f86198d |
Close
Hashes for webp-0.1.8-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3da0147a0ae484f7cd7192e5667cad46387ad384699e0f71089fcedfd3d32818 |
|
MD5 | f80600ce7ecf98b56946b094d4c88020 |
|
BLAKE2b-256 | b85200587ca5edc3315040dd6cffc1b14638a125fc54ad0a4b40bee4f7e9d108 |
Close
Hashes for webp-0.1.8-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac94eefc5f88c790010512b9cfbddb047a60665f298b575c246158ff8e383908 |
|
MD5 | 945b7067d191c229bef53b8f72563474 |
|
BLAKE2b-256 | dbf3d987fa09fea6adc68950a831a63b765f9757f8c14da1ca741f4fc71b99e1 |
Close
Hashes for webp-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6de10c45ca19904c5d56cf037d5667e7ca4a057bb9577e885b9d41a0e2ddf2ad |
|
MD5 | e1bc27e42c3dda73cfa8bae88ed3e2a3 |
|
BLAKE2b-256 | bb452303a54f3aa5ea1e6b8bb36731ef171ad24fb564a5492c268293c3926564 |
Close
Hashes for webp-0.1.8-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5f19443ec1c3dc2ea3637cda3fce5519fd18d0d68d614b4dce30a26e1e2a412 |
|
MD5 | a979a9ee68a1d2d2b936282e7d9be431 |
|
BLAKE2b-256 | 76ad033b3c99a10c66325609838989c9dd4b356e707f3bb1e0df071fece2e5ed |
Close
Hashes for webp-0.1.8-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0588820a4e4c98106e5909d7ca9b2778e715ced2dad21723820054aac8434cd3 |
|
MD5 | a11a6684c6ce828b3077d7cbcc2edde9 |
|
BLAKE2b-256 | d41c5d7b92af87cfae2bfeed550d6d69cd7ee0b366b5365038d2991bfea4ad2b |
Close
Hashes for webp-0.1.8-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a748cbe762de179beaf8c648a803aa749b974c1410a84ba89919e623a1abb806 |
|
MD5 | ad98d841b5881f6c7f37bd53045d4d98 |
|
BLAKE2b-256 | d164dc3e870123e8a54ee8d34e69da04446df0f4ad64956b5f81f05afb4a1ab9 |
Close
Hashes for webp-0.1.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c61a6e85c7c48f84c0a6d0d5ff39a427fad7d27313a0e64befe5f38057e8df61 |
|
MD5 | bc1840404a0b42cd1b3e6fe18ae656b4 |
|
BLAKE2b-256 | 180cb7a3fa8ceb0f6fe6b7cb89bdbd3ee888f30aaf0245bb6a14ca9f0eda67d7 |
Close
Hashes for webp-0.1.8-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 325d940d7e63fa16847bc90401f08d6b512c9101d344f693f5059b5022e3c45a |
|
MD5 | e00d32f96caf643ac037f474f2585e56 |
|
BLAKE2b-256 | d9f7f71059f5c6f9b1b8b3fe1a49baf2ac394bbdd1ef1a357019812210cf8242 |
Close
Hashes for webp-0.1.8-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 565dabed468aeafd7826e2a71c0ed3c12b28625e73f1f3d6d4ff86551fa43254 |
|
MD5 | 64f09d89a213a682acbdd96bba0ae5f3 |
|
BLAKE2b-256 | 345f81023fe72fd37b9338b720b9ec09cba0410af9fdec35f32334d23e3b1237 |