Skip to main content

A Python package that provides a command-line interface (CLI) for converting images to the WebP format. It supports various image formats and allows for resizing images based on predefined rules.

Project description

img-to-webp

Build and Test

img-to-webp is a Python package that provides a command-line interface (CLI) for converting images to the WebP format. It supports various image formats and allows for resizing images based on predefined rules.

Features

  • Convert images from various formats (PNG, JPG, JPEG, GIF, BMP, TIFF) to WebP.
  • Resize images using different modes: cover, contain, fill, or none.
  • Define custom resizing rules based on filename patterns.
  • Option to overwrite existing files.
  • Verbose logging for detailed processing information.

Installation

To install the package for a user, you can use pip:

pip install -U img-to-webp

Usage

Command-Line Interface

You can use the CLI to process images by specifying the input and output directories, along with other options.

img-to-webp --input-dir INPUT_DIR [options]

Options

  • --input-dir: Directory containing the images to be processed.
  • --output-dir: Directory where the processed images will be saved. If not specified, the output directory will be the same as the input directory.
  • --default-resize-mode: Mode for resizing images (cover, contain, fill, none).
  • --default-size: Default size for resizing images (width, height).
  • --quality: Quality of the output WebP images (0-100).
  • --overwrite: Overwrite existing files in the output directory.
  • --verbose: Enable verbose logging.
  • --config: Path to a YAML configuration file.

Example

img-to-webp --input-dir ./images \
    --output-dir ./webp_images \
    --default-resize-mode cover \
    --default-size 256 256 \
    --quality 80 \
    --overwrite \
    --verbose

Configuration File

You can also use a YAML configuration file to specify the settings. The CLI will merge the settings from the configuration file with the command-line arguments.

input_dir: ./images
output_dir: ./webp_images
default_resize_mode: cover
resize_rules:
  - pattern: ".*_small.*"
    size: [ 128, 128 ]
    mode: contain
  - pattern: ".*_large.*"
    size: [ 512, 512 ]
    mode: cover
default_size: [ 256, 256 ]

Using Configuration File

img-to-webp --config config.yaml --overwrite

Development

This project uses uv Python package manager. To set up the development environment, clone the repository and install the dependencies:

git clone https://github.com/nipunchamikara/img-to-webp.git
cd img-to-webp
uv venv
source .venv/bin/activate
uv sync --all-groups

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Contact

For any questions or issues, please open an issue on the GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

img_to_webp-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file img_to_webp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for img_to_webp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d43bc0f8fc656a9b0235b9d3c22e2f4024e047ad8ab0c7bd2dd2e6b2a06f6ed
MD5 7206d5c010337a14911c9f2fd7d844d5
BLAKE2b-256 ec77cc7ecdc3df6cbdbba90e693f4cb4084784c7b337e2ebe64de7f234e8d83c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page