Skip to 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.

License

Notifications You must be signed in to change notification settings

nipunchamikara/img-to-webp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, use pip:

pip install 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.

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages