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.3.0.tar.gz
(18.8 kB
view hashes)
Built Distributions
webp-0.3.0-cp312-cp312-win_arm64.whl
(188.4 kB
view hashes)
webp-0.3.0-cp312-cp312-win_amd64.whl
(216.9 kB
view hashes)
webp-0.3.0-cp311-cp311-win_arm64.whl
(188.4 kB
view hashes)
webp-0.3.0-cp311-cp311-win_amd64.whl
(216.9 kB
view hashes)
webp-0.3.0-cp310-cp310-win_arm64.whl
(188.4 kB
view hashes)
webp-0.3.0-cp310-cp310-win_amd64.whl
(216.8 kB
view hashes)
webp-0.3.0-cp39-cp39-win_arm64.whl
(188.4 kB
view hashes)
webp-0.3.0-cp39-cp39-win_amd64.whl
(216.8 kB
view hashes)
webp-0.3.0-cp38-cp38-win_amd64.whl
(216.8 kB
view hashes)
Close
Hashes for webp-0.3.0-cp312-cp312-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e15336927e14320acea89b34350918d201c1ab2627c00d165dffceb5356ec246 |
|
MD5 | f2e708e8a5331989ceac7a2a04e527ab |
|
BLAKE2b-256 | ac1539fc71f0c33caadb06e4e49409045ce2d1694455c357ec86365b5383f8eb |
Close
Hashes for webp-0.3.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32d4c2e692cb367e1deb3696a4bca43dc4ac855cc53b265a5e2fce338e633377 |
|
MD5 | 39ab771b9a9f99923d5139100b011d96 |
|
BLAKE2b-256 | 9ac0640881d0255b2587f30e5d5cb923cf4a8277d013effb0a33753d361becfa |
Close
Hashes for webp-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a70886ccad12f99286979e5615f984bfd76aff4d48861618340e8b3b0b8d2114 |
|
MD5 | 85f699094b9e288848ccee0657ebb9c6 |
|
BLAKE2b-256 | 8c08f934d28a0e30835660ae7fed92f2d56cf4a3637059fef4904ebad09b19b9 |
Close
Hashes for webp-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddfb90c5a726818e4a2ff9006a2f3c3168957fff56291081e64da9c54af3e6d1 |
|
MD5 | d9f501ee9a48c5bcfc715316600ae5d2 |
|
BLAKE2b-256 | 088f64822f39f4acc05e34f60e234a306208550d4a237124b49d8c445b855772 |
Close
Hashes for webp-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57028316253ef07b7c985aed2d635d6a9e7b77dd369aba35c17cb77f2e24fccb |
|
MD5 | 0484b06ee387bb6682e15124a68bbf87 |
|
BLAKE2b-256 | 388db896ec4365da6b195e4f1691c6a9c563eade3b45df1b074e00f01debd65b |
Close
Hashes for webp-0.3.0-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edb6b911fdd98fc8caa5e28070ef398a9c92c6c27d435d13ebe0061cb1bf67af |
|
MD5 | ca75fb2a2589d70e236e3e455358117c |
|
BLAKE2b-256 | 67b4810ec7773184ba2ca92dd7eec1db43b0600910d03edd5b872f9f609e083a |
Close
Hashes for webp-0.3.0-cp311-cp311-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69f56d5e40020559ab967ff38fd37895886bb752045ebbba83750d157f692868 |
|
MD5 | 665cf57a5a98c041ab4ef0daee422d30 |
|
BLAKE2b-256 | cdadce2c50ef994b03405efd8a7408eef0579706bd6ea38be958f14ee8265165 |
Close
Hashes for webp-0.3.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e228715cb7102610bd78cf9b626b7dd0fb0ea89fc36be483db6c05760fa89b7 |
|
MD5 | 6bb071e70ede0f0d8900ac98831d2d79 |
|
BLAKE2b-256 | c7d7f944e317ccc208eb5dbf3e323434b56b40e7d466f05e23ecc504b660813d |
Close
Hashes for webp-0.3.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 958e38357fa0eb60ce6352020210a90fd1954a6270f2daa758ea404f85d7739f |
|
MD5 | fe192cc692a9b03f7cbcf18a2cdd68e8 |
|
BLAKE2b-256 | b9bd9877f72dffd80fe9fed89e11f3a23e35ae2db4761daeaf8f92665ed90f16 |
Close
Hashes for webp-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e290cc3db157a9557fc7d0c9044f83e5ed518c92019067ac87433eb37e28bf0 |
|
MD5 | 63ea4f5a10eefaa4147f0ef4a1231a62 |
|
BLAKE2b-256 | c0b294e266f71f63cf81c32e2bacc3e156364b26e24ab796aea7338e92e594d8 |
Close
Hashes for webp-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3901024c0214b43f0830d18dc95fb681e5e2d150d92c84b734616961b52e5f92 |
|
MD5 | 5074b2bd4fe3ffe759c888ed379de2f0 |
|
BLAKE2b-256 | 8345548a9fc944a9618c5ca33d0cf98459021df3fb667229f480e14743103100 |
Close
Hashes for webp-0.3.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17c66319ded46c0b858424f5a8e132b1fc233106784027dede17a33bffbe508b |
|
MD5 | 3dd0c1af0d311dc81e3259cd15b131c1 |
|
BLAKE2b-256 | 32089b9f1724d0222f69dfba8e4ff1b2594a97ce9be98c469eb7416f5a90f43b |
Close
Hashes for webp-0.3.0-cp310-cp310-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d0136be5a1d78d283a9df4542ab18a94ffa8a71eb692d63f459c5567b2a0796 |
|
MD5 | 326b743948ee624b32313654465c14cb |
|
BLAKE2b-256 | 6ed0fe7998f2575e0444498c2ec86d15abc1fbfc2286e7a71df4bd23f85c45d9 |
Close
Hashes for webp-0.3.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55e939762c504797c3ff1c26828961986ee1b04452515910077a22b85d4214fd |
|
MD5 | 1664c11a6073bc2287f735dc9fa6bf10 |
|
BLAKE2b-256 | 4a4b006058628b74301604f098fc0d721dee8060ba750c70accf6d189408a863 |
Close
Hashes for webp-0.3.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 302c213370b549e59fba03589bcdf033723ad46d0e813843b95d0d80c3c7a903 |
|
MD5 | b9215aff2d09ec73806461fda73bf844 |
|
BLAKE2b-256 | 058847972b0fb39cb2ddad43c7817c2ae1a2b76d8ecfa3bebc84a69ee837290b |
Close
Hashes for webp-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01c8ee5824984b2c83696b134f9d6d468a768d3e0bffb09e82f9d39027874755 |
|
MD5 | 5dbcd73c085865610f21b19d1d3107c7 |
|
BLAKE2b-256 | 6af3d867b6380a7e031fdd22002f27e48028f8ce11629827da95b7a4a7c7b089 |
Close
Hashes for webp-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4eec57bf92d5871a291d790e73b04e829c7703c25a141eff01da28141e50d18 |
|
MD5 | c1151451beb74c56a2d7c5e1ef7e2477 |
|
BLAKE2b-256 | 1ae32fa462b4e575748897f5d782b3565cc604e062f44c8300d74881880908da |
Close
Hashes for webp-0.3.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef131d8af4552f870f5984a96671600bf29558ab7c3bf5fa2a010bfaefb4ff81 |
|
MD5 | e8143a69d48e7b5bd97e75759bad88a0 |
|
BLAKE2b-256 | a3abf533569acf8d9f3bdcaf88823266d7a02c11e5e356b5625ca918fac3b85f |
Close
Hashes for webp-0.3.0-cp39-cp39-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f77f1a387e0c972f22163eb503b2d4a7e716bb352f6a06774111bcb62e5a60e7 |
|
MD5 | 13b7a7c9157462b12cf24a44275825cc |
|
BLAKE2b-256 | 69b6657fc16641e84c7271017844be132884fcf390deafd031cc341ab96897a7 |
Close
Hashes for webp-0.3.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b789fc057994085877f6ea0a4980aaa6ec95335ff7dc20072a4ff69049cf3df6 |
|
MD5 | 16433c0302f881d9d66e6e2db5686cef |
|
BLAKE2b-256 | be4305ea60eba99d4cf8ba3f4c513df83c0fcaca1739b74592b5534184085be6 |
Close
Hashes for webp-0.3.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4e0237bd3e4fce1d040b4fcc230c156a86b5e6468d9d69c5e5c2c92a35c9fbd |
|
MD5 | 8c735a1b81c5e7980549ef6a3f11f6b3 |
|
BLAKE2b-256 | 25def0a16e052f73cd837f1b50954ce0715103321b29120dd3cd696e37cc434d |
Close
Hashes for webp-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a41dd59cd254e922995db5d373d64ec09af53eedf772e9b36adaf7394af024f9 |
|
MD5 | 0325a3ad181528cf0f666397f7415aad |
|
BLAKE2b-256 | 2830aa6c11e1e70b797b2c7ef061d592470d9de9769cb60079e13d54e277635f |
Close
Hashes for webp-0.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1bd6dfb54ca66ee05ce83135641d98f196374202e139455ed59b7c2ec7cd150 |
|
MD5 | bb64748c5f1a95eebcf46e0686359099 |
|
BLAKE2b-256 | cd68d32f46482dfc9fcd08e76a0c1d8d40cdf581d6940211bcc5bf564d0cd939 |
Close
Hashes for webp-0.3.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25b423412035d8888cb4d2613ef235b42bba14cd26ef04a4a28da9b39af433e7 |
|
MD5 | 294c62dc53566c6eae33317cb31400d9 |
|
BLAKE2b-256 | 2c5c196d83111b2b92896427e95fb06fb1723069e2d7862ae5bffac0d04b9067 |
Close
Hashes for webp-0.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6256e63ce90331cddf5f6a3fda3b7e11a5d35284230c320e4a7614b43d9f54d7 |
|
MD5 | a284d86cb3aafef88f9375d7841603c0 |
|
BLAKE2b-256 | d6fdae9fd901f0b277677c3a8615a33f485c8e9e6e630f84a1e90b12415c9e0f |
Close
Hashes for webp-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe9ee71c2cf53fa9d1da3a22a7ff49e3d7734c335c48066c4a08be88d4b682c0 |
|
MD5 | 3e0c174f374b7fc862b2d2dc4aee1dc5 |
|
BLAKE2b-256 | 800dc69de0c2b2ac2c829302d7d995e73e9858616d34571f38e7a9f017057f84 |
Close
Hashes for webp-0.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dff7117a5eaff19e7d3f71be9bb775e52a35cc14dd03e58ccd2d41bc57feedd2 |
|
MD5 | c360001cab36e8869473d81bc7d8ede8 |
|
BLAKE2b-256 | 116be2f4d148b17cd65fbe04f6101c0549c7c216f48635450b88b1eb306c4076 |
Close
Hashes for webp-0.3.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fd0abcfe53fd3cca3df29286440f6909304c5e723b76ece1142097c6566f5f |
|
MD5 | 43e11294424a5d50c6ae9fc6b432f303 |
|
BLAKE2b-256 | c94fac2970043151ea1e6da5ca22ffe8c79225c6d43f150d1d4e1fde440a9ffd |