Package: webp
WebP Python bindingsInstallationpipinstallwebpOn Windows you may encounter the following error during installation:conans.errors.ConanException: 'settings.compiler' value not definedThis means that you need to install a C compiler and configure Conan so that it knows which
compiler to use. Seehttps://github.com/anibali/pywebp/issues/20for more details.RequirementsPython 3.8+UsageimportwebpSimple API# Save an imagewebp.save_image(img,'image.webp',quality=80)# Load an imageimg=webp.load_image('image.webp','RGBA')# Save an animationwebp.save_images(imgs,'anim.webp',fps=10,lossless=True)# Load an animationimgs=webp.load_images('anim.webp','RGB',fps=10)If you prefer working with numpy arrays, use the functionsimwrite,imread,mimwrite,
andmimreadinstead.Advanced API# Encode a PIL image to WebP in memory, with encoder hintspic=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 arraywithopen('image.webp','rb')asf:webp_data=webp.WebPData.from_buffer(f.read())arr=webp_data.decode(color_mode=WebPColorMode.BGR)# Save an animationenc=webp.WebPAnimEncoder.new(width,height)timestamp_ms=0forimginimgs:pic=webp.WebPPicture.from_pil(img)enc.encode_frame(pic,timestamp_ms)timestamp_ms+=250anim_data=enc.assemble(timestamp_ms)withopen('anim.webp','wb')asf:f.write(anim_data.buffer())# Load an animationwithopen('anim.webp','rb')asf:webp_data=webp.WebPData.from_buffer(f.read())dec=webp.WebPAnimDecoder.new(webp_data)forarr,timestamp_msindec.frames():# `arr` contains decoded pixels for the frame# `timestamp_ms` contains the _end_ time of the framepassFeaturesPicture encoding/decodingAnimation encoding/decodingAutomatic memory managementSimple API for working withPIL.ImageobjectsNot implementedEncoding/decoding still images in YUV color modeAdvanced muxing/demuxing (color profiles, etc.)Expose all useful fieldsDeveloper notesSetting upInstallmambaandconda-lock. The easiest way to do this is by installingMambaforgeand then
runningmamba install conda-lock.Create and activate the Conda environment:$conda-lockinstall-nwebp$mambaactivatewebpInstall PyPI dependencies:$pdminstall-G:allRunning tests$pytesttests/Cutting a new releaseEnsure that tests are passing and everything is ready for release.Create and push a Git tag:$gittagv0.1.6$gitpush--tagsDownload 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:$twineuploadwebp-*.tar.gzwebp-*.whlBump the version number inpyproject.tomland create a commit, signalling the start of development on the next version.These files should also be added to a GitHub release.Known issuesAn 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 breakswebp.load_imageswhen 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.