webp


Namewebp JSON
Version 0.4.0 PyPI version JSON
download
home_pageNone
SummaryPython bindings for WebP
upload_time2024-06-09 07:05:24
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # WebP Python bindings

[![Build status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fanibali%2Fpywebp%2Fbadge&label=build&logo=none)](https://actions-badge.atrox.dev/anibali/pywebp/goto)
[![License](https://img.shields.io/github/license/anibali/pywebp.svg)](https://github.com/anibali/pywebp/blob/master/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/webp)](https://pypi.org/project/webp/)
[![GitHub](https://img.shields.io/github/stars/anibali/pywebp?style=social)](https://github.com/anibali/pywebp)

## Installation

```sh
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

```python
import webp
```

### Simple API

```python
# 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

```python
# 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

1. Install `mamba` and `conda-lock`. The easiest way to do this is by installing
   [Mambaforge](https://github.com/conda-forge/miniforge#mambaforge) and then
   running `mamba install conda-lock`. 
2. Create and activate the Conda environment:
   ```console
   $ conda-lock install -n webp
   $ mamba activate webp
   ```
3. Install PyPI dependencies:
   ```console
   $ pdm install -G:all
   ```

### Running tests

```console
$ pytest tests/
```

### Cutting a new release

1. Ensure that tests are passing and everything is ready for release.
2. Create and push a Git tag:
   ```console
   $ git tag v0.1.6
   $ git push --tags
   ```
3. Download the artifacts from GitHub Actions, which will include the source distribution tarball and binary wheels.
4. Create a new release on GitHub from the tagged commit and upload the packages as attachments to the release.
5. Also upload the packages to PyPI using Twine:
   ```console
   $ twine upload webp-*.tar.gz webp-*.whl
   ```
6. 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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "webp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Aiden Nibali <dismaldenizen@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/07/aa/2a64b903367eb3be5e0b5f89e6e6e54162281712d3a0512dbdfaf03ea97f/webp-0.4.0.tar.gz",
    "platform": null,
    "description": "# WebP Python bindings\n\n[![Build status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fanibali%2Fpywebp%2Fbadge&label=build&logo=none)](https://actions-badge.atrox.dev/anibali/pywebp/goto)\n[![License](https://img.shields.io/github/license/anibali/pywebp.svg)](https://github.com/anibali/pywebp/blob/master/LICENSE)\n[![PyPI](https://img.shields.io/pypi/v/webp)](https://pypi.org/project/webp/)\n[![GitHub](https://img.shields.io/github/stars/anibali/pywebp?style=social)](https://github.com/anibali/pywebp)\n\n## Installation\n\n```sh\npip install webp\n```\n\nOn Windows you may encounter the following error during installation:\n\n```\nconans.errors.ConanException: 'settings.compiler' value not defined\n```\n\nThis means that you need to install a C compiler and configure Conan so that it knows which\ncompiler to use. See https://github.com/anibali/pywebp/issues/20 for more details.\n\n### Requirements\n\n* Python 3.8+\n\n## Usage\n\n```python\nimport webp\n```\n\n### Simple API\n\n```python\n# Save an image\nwebp.save_image(img, 'image.webp', quality=80)\n\n# Load an image\nimg = webp.load_image('image.webp', 'RGBA')\n\n# Save an animation\nwebp.save_images(imgs, 'anim.webp', fps=10, lossless=True)\n\n# Load an animation\nimgs = webp.load_images('anim.webp', 'RGB', fps=10)\n```\n\nIf you prefer working with numpy arrays, use the functions `imwrite`, `imread`, `mimwrite`,\nand `mimread` instead.\n\n### Advanced API\n\n```python\n# Encode a PIL image to WebP in memory, with encoder hints\npic = webp.WebPPicture.from_pil(img)\nconfig = WebPConfig.new(preset=webp.WebPPreset.PHOTO, quality=70)\nbuf = pic.encode(config).buffer()\n\n# Read a WebP file and decode to a BGR numpy array\nwith open('image.webp', 'rb') as f:\n  webp_data = webp.WebPData.from_buffer(f.read())\n  arr = webp_data.decode(color_mode=WebPColorMode.BGR)\n\n# Save an animation\nenc = webp.WebPAnimEncoder.new(width, height)\ntimestamp_ms = 0\nfor img in imgs:\n  pic = webp.WebPPicture.from_pil(img)\n  enc.encode_frame(pic, timestamp_ms)\n  timestamp_ms += 250\nanim_data = enc.assemble(timestamp_ms)\nwith open('anim.webp', 'wb') as f:\n  f.write(anim_data.buffer())\n\n# Load an animation\nwith open('anim.webp', 'rb') as f:\n  webp_data = webp.WebPData.from_buffer(f.read())\n  dec = webp.WebPAnimDecoder.new(webp_data)\n  for arr, timestamp_ms in dec.frames():\n    # `arr` contains decoded pixels for the frame\n    # `timestamp_ms` contains the _end_ time of the frame\n    pass\n```\n\n## Features\n\n* Picture encoding/decoding\n* Animation encoding/decoding\n* Automatic memory management\n* Simple API for working with `PIL.Image` objects\n\n### Not implemented\n\n* Encoding/decoding still images in YUV color mode\n* Advanced muxing/demuxing (color profiles, etc.)\n* Expose all useful fields\n\n## Developer notes\n\n### Setting up\n\n1. Install `mamba` and `conda-lock`. The easiest way to do this is by installing\n   [Mambaforge](https://github.com/conda-forge/miniforge#mambaforge) and then\n   running `mamba install conda-lock`. \n2. Create and activate the Conda environment:\n   ```console\n   $ conda-lock install -n webp\n   $ mamba activate webp\n   ```\n3. Install PyPI dependencies:\n   ```console\n   $ pdm install -G:all\n   ```\n\n### Running tests\n\n```console\n$ pytest tests/\n```\n\n### Cutting a new release\n\n1. Ensure that tests are passing and everything is ready for release.\n2. Create and push a Git tag:\n   ```console\n   $ git tag v0.1.6\n   $ git push --tags\n   ```\n3. Download the artifacts from GitHub Actions, which will include the source distribution tarball and binary wheels.\n4. Create a new release on GitHub from the tagged commit and upload the packages as attachments to the release.\n5. Also upload the packages to PyPI using Twine:\n   ```console\n   $ twine upload webp-*.tar.gz webp-*.whl\n   ```\n6. Bump the version number in `pyproject.toml` and create a commit, signalling the start of development on the next version.\n\nThese files should also be added to a GitHub release.\n\n## Known issues\n\n* An animation where all frames are identical will \"collapse\" in on itself,\n  resulting in a single frame. Unfortunately, WebP seems to discard timestamp\n  information in this case, which breaks `webp.load_images` when the FPS\n  is specified.\n* There are currently no 32-bit binaries of libwebp uploaded to Conan Center. If you are running\n  32-bit Python, libwebp will be built from source.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python bindings for WebP",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/anibali/pywebp"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "81b45772851d64a5be2ea711d3fca988742d5f9ce28cf6c13fb8e4ed8a4909d9",
                "md5": "b22976146c3b0b6c04fa4022419332c4",
                "sha256": "697f5180df0f6ea70659872f835d4727009492e5d9550772a562e559fc06fc75"
            },
            "downloads": -1,
            "filename": "webp-0.4.0-cp38-abi3-macosx_10_9_universal2.whl",
            "has_sig": false,
            "md5_digest": "b22976146c3b0b6c04fa4022419332c4",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 605451,
            "upload_time": "2024-06-09T07:05:08",
            "upload_time_iso_8601": "2024-06-09T07:05:08.167014Z",
            "url": "https://files.pythonhosted.org/packages/81/b4/5772851d64a5be2ea711d3fca988742d5f9ce28cf6c13fb8e4ed8a4909d9/webp-0.4.0-cp38-abi3-macosx_10_9_universal2.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f75ca99e30271160a1a5eaa9a886c882cf8a8f4db178b63e878523e768dc364d",
                "md5": "63f2c4349227b4238b392c6488781f05",
                "sha256": "5a58a04d74c3323a760cf1b581f5c0ea36f8df426065f434c5fb4c7eb06d2e26"
            },
            "downloads": -1,
            "filename": "webp-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "63f2c4349227b4238b392c6488781f05",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 356933,
            "upload_time": "2024-06-09T07:05:11",
            "upload_time_iso_8601": "2024-06-09T07:05:11.250265Z",
            "url": "https://files.pythonhosted.org/packages/f7/5c/a99e30271160a1a5eaa9a886c882cf8a8f4db178b63e878523e768dc364d/webp-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ceb335269831a40129b52091e4f8837d6a07c0063221e92805203ac16b9426ca",
                "md5": "2b2f35c35f4aa9361f94ee8c4ccb7fb6",
                "sha256": "ca6aa8cdff582794146dfecd24aeb2b7986559cca5a1d12b504ffca6d87417d4"
            },
            "downloads": -1,
            "filename": "webp-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "2b2f35c35f4aa9361f94ee8c4ccb7fb6",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 405145,
            "upload_time": "2024-06-09T07:05:14",
            "upload_time_iso_8601": "2024-06-09T07:05:14.685906Z",
            "url": "https://files.pythonhosted.org/packages/ce/b3/35269831a40129b52091e4f8837d6a07c0063221e92805203ac16b9426ca/webp-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c07178751690f32c8bf80d19d2809b4faca5e51c13bcee0a3139941692cd858e",
                "md5": "cb6683a769b69f977d5888547f9e8736",
                "sha256": "016bbea5bc61708708873ecd75dbb29552d28e6bd9180b4e1352d3b1d6811f01"
            },
            "downloads": -1,
            "filename": "webp-0.4.0-cp38-abi3-musllinux_1_1_x86_64.whl",
            "has_sig": false,
            "md5_digest": "cb6683a769b69f977d5888547f9e8736",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 412239,
            "upload_time": "2024-06-09T07:05:17",
            "upload_time_iso_8601": "2024-06-09T07:05:17.375503Z",
            "url": "https://files.pythonhosted.org/packages/c0/71/78751690f32c8bf80d19d2809b4faca5e51c13bcee0a3139941692cd858e/webp-0.4.0-cp38-abi3-musllinux_1_1_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "638d9a79d73249c63e0d216c832697d76072c9f2b0cb09792618972ba9fe3133",
                "md5": "61775ca8f517367dc537adb010ec0725",
                "sha256": "3c5f7718a3e9e19018ed31765273ff323bdf5820d8255d0001d66ea9c3489d0a"
            },
            "downloads": -1,
            "filename": "webp-0.4.0-cp38-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "61775ca8f517367dc537adb010ec0725",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 218158,
            "upload_time": "2024-06-09T07:05:19",
            "upload_time_iso_8601": "2024-06-09T07:05:19.750753Z",
            "url": "https://files.pythonhosted.org/packages/63/8d/9a79d73249c63e0d216c832697d76072c9f2b0cb09792618972ba9fe3133/webp-0.4.0-cp38-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a3ffe7e4245e8cdeee42a7e666bd80e0e48b255405508ae87997640f73b13384",
                "md5": "214b0b51e0b5e58902f86aac023ca6c6",
                "sha256": "ed479890ca954404925e99c245fb8e456903ab5e17884081304f64d4434763e2"
            },
            "downloads": -1,
            "filename": "webp-0.4.0-cp38-abi3-win_arm64.whl",
            "has_sig": false,
            "md5_digest": "214b0b51e0b5e58902f86aac023ca6c6",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 189703,
            "upload_time": "2024-06-09T07:05:22",
            "upload_time_iso_8601": "2024-06-09T07:05:22.484903Z",
            "url": "https://files.pythonhosted.org/packages/a3/ff/e7e4245e8cdeee42a7e666bd80e0e48b255405508ae87997640f73b13384/webp-0.4.0-cp38-abi3-win_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "07aa2a64b903367eb3be5e0b5f89e6e6e54162281712d3a0512dbdfaf03ea97f",
                "md5": "6e4fa226554b98bf83093a5dad2893f4",
                "sha256": "9265565839ac938327705c5fbfa3d8ceeeb9b5a2c1c3367231caa0bad29464c7"
            },
            "downloads": -1,
            "filename": "webp-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6e4fa226554b98bf83093a5dad2893f4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 20082,
            "upload_time": "2024-06-09T07:05:24",
            "upload_time_iso_8601": "2024-06-09T07:05:24.390877Z",
            "url": "https://files.pythonhosted.org/packages/07/aa/2a64b903367eb3be5e0b5f89e6e6e54162281712d3a0512dbdfaf03ea97f/webp-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-09 07:05:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "anibali",
    "github_project": "pywebp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "webp"
}
        
Elapsed time: 0.29907s