Skip to main content

webimg: Smart Asset & Image Optimizer for Web/Social Media

A high-performance, modular Python CLI tool and daemon folder watcher built to optimize images (PNG, JPG, JPEG) into next-generation web formats (WebP and AVIF), automatically generate responsive variants, and strip sensitive EXIF metadata for privacy protection.

Powered by multiprocessing (concurrent.futures.ProcessPoolExecutor) to maximize throughput on multi-core CPUs.


Key Features

  • Batch Compression & Format Conversion:

    • Converts traditional formats (PNG, JPG, JPEG, BMP, TIFF) to modern web formats (WebP and AVIF).
    • Fine-grained visual quality control (--quality 1-100, --lossless, --effort 0-6).
    • Automatically handles transparency (RGBA) and color modes (CMYK -> RGB).
  • Responsive Variant Generator:

    • Automatically generates standard web breakpoints (e.g. 300px, 768px, 1200px) using high-fidelity Lanczos downscaling.
    • Built-in presets: --preset web, --preset social, --preset avatar, --preset thumb.
    • Smart aspect ratio preservation without upscaling smaller images.
  • Privacy & Metadata Stripping:

    • Strips privacy-sensitive EXIF tags by default (GPS locations, camera make/model, timestamps, serial numbers).
    • Automatically transposes image pixels based on EXIF orientation prior to stripping, preventing upside-down or sideways photos.
    • Option to retain metadata when necessary via --keep-exif.
  • Real-Time Folder Watcher (Daemon Mode):

    • Continuously monitors an input directory using watchdog.
    • Automatically detects new or updated images, debounces write events, and exports optimized variants to the output directory.
  • Parallel Concurrency & Rich CLI UX:

    • Multi-core processing using Python's ProcessPoolExecutor.
    • Visual terminal interface using typer and rich with live progress bars, file completion stats, and compression summary tables.

Project Architecture

webimg-optimizer/
├── pyproject.toml              # PEP 621 packaging with 'webimg' CLI script entrypoint
├── requirements.txt            # Project dependencies (Pillow, pillow-heif, typer, rich, watchdog)
├── README.md                   # Full documentation and execution guide
├── tests/
│   ├── __init__.py
│   ├── test_converter.py       # Unit tests: WebP, AVIF, responsive sizing, corrupt files
│   ├── test_metadata.py        # Unit tests: EXIF stripping, --keep-exif, inspection
│   └── test_watcher.py         # Unit tests: Real-time watcher event handling
└── webimg/
    ├── __init__.py             # Package version and metadata
    ├── cli.py                  # Typer CLI application (optimize, watch, info, version)
    ├── config.py               # Enums, Presets, and configuration dataclasses
    ├── core/
    │   ├── __init__.py
    │   ├── converter.py        # Resizing, encoding, and multiprocessing pool executor
    │   ├── metadata.py         # EXIF extraction, orientation transposition, stripping
    │   └── watcher.py          # Watchdog file system event listener with debouncing
    └── utils/
        ├── __init__.py
        ├── helpers.py          # File scanners, format helpers, byte calculators
        └── logger.py           # Rich console logger, status badges, and summary tables

Installation

1. Prerequisites

  • Python 3.9 or higher.

2. Install Package

Install from PyPI:

pip install webimg-optimizer

Or install from source repository in editable mode:

git clone https://github.com/adewanggar/webimg-optimizer.git
cd webimg-optimizer
pip install -e .

Note for Windows Users: If your Python Scripts directory is not in your system PATH, you can invoke the CLI using python -m webimg.cli [COMMAND] or add %APPDATA%\Python\Python3xx\Scripts to your environment variables.


CLI Usage and Examples

1. Batch Optimize (webimg optimize)

Optimize a single file or an entire directory:

# Optimize all images in a folder to WebP (default quality 80)
webimg optimize ./assets/images/ -o ./dist/images/

# Convert images to both WebP and AVIF
webimg optimize ./photos/ -o ./optimized/ -f webp -f avif

# Generate responsive web variants (300px, 768px, 1200px) + original size
webimg optimize ./photos/ -o ./optimized/ -w 300,768,1200 -q 85

# Use a built-in preset (web, social, avatar, thumb)
webimg optimize ./photos/ -o ./optimized/ --preset web

# Retain EXIF metadata (disabled by default for privacy)
webimg optimize ./photos/ -o ./optimized/ --keep-exif

# Adjust concurrency workers (e.g. 4 workers)
webimg optimize ./photos/ -o ./optimized/ --workers 4

CLI Options for optimize:

Option Flag Description Default
--output -o Output destination directory <input>/optimized
--format -f Target format (webp, avif, all, original) webp
--quality -q Compression quality (1 - 100) 80
--widths -w Comma-separated variant widths in pixels (e.g. 300,768,1200) None
--preset -p Responsive preset (none, web, social, avatar, thumb) none
--keep-exif Retain camera/GPS EXIF metadata False (strips EXIF)
--workers Number of parallel worker processes CPU core count
--recursive -r Recursively scan subdirectories True
--lossless Enable lossless compression (WebP) False
--effort Encoding effort level (0 to 6) 4
--no-orig Do not output original size if variant widths are set False

2. Real-Time Folder Watcher (webimg watch)

Start a background daemon that monitors an input directory for new or modified images and automatically processes them into the output directory:

# Watch a folder and output WebP variants automatically
webimg watch ./incoming_uploads/ -o ./cdn_assets/

# Watch with responsive variants and both WebP & AVIF formats
webimg watch ./incoming_uploads/ -o ./cdn_assets/ -f webp -f avif --preset web -q 82
  • Debouncing: Prevents incomplete file processing while an image is still being copied or uploaded over the network.
  • Graceful Shutdown: Stop the watcher anytime with Ctrl + C.

3. Metadata & Privacy Inspection (webimg info)

Inspect image dimensions, color mode, file size, and check whether sensitive EXIF metadata (camera model, GPS coordinates) is exposed:

webimg info ./photos/sample_camera.jpg

Responsive Presets

Preset Target Widths (px) Typical Use Case
web 320, 768, 1200 Standard responsive website layouts (mobile, tablet, desktop)
social 1080, 1200 Social media feeds (Instagram, LinkedIn, Twitter/X landscape)
avatar 128, 256, 512 User profiles and thumbnails
thumb 150, 300 Product listings and gallery thumbnails

Generated filenames include the width suffix (e.g. banner_300w.webp, banner_768w.webp, banner.webp).


Running Tests

Run the automated unit test suite with pytest:

python -m pytest tests/ -v

Tests cover:

  • WebP and AVIF encoding fidelity
  • Responsive resizing without upscaling
  • Transparency (RGBA) preservation
  • EXIF stripping vs --keep-exif
  • Graceful handling of corrupted or zero-byte files
  • Folder watcher event handling
  • Multi-worker multiprocessing pool execution

Download files

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

Source Distribution

webimg_optimizer-0.1.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

webimg_optimizer-0.1.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file webimg_optimizer-0.1.0.tar.gz.

File metadata

  • Download URL: webimg_optimizer-0.1.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for webimg_optimizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d45a2a8c0a2531d2d6b725cb6074343710510ef940fa2e1e865c6d1644ca436a
MD5 c955de326a1cf9c43f090aae126d7700
BLAKE2b-256 aa0ceface79a12d6804227e58a81aa0c9faae7329ec75e84e66daadc40a986c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for webimg_optimizer-0.1.0.tar.gz:

Publisher: workflow.yml on adewanggar/webimg-optimizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for webimg_optimizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c5dcf9475be8765e1c6440fcf7acbea2e5d0e693b427dc1cbb5b6d4079489e4
MD5 dded85deab26cf5a9dc11b16416bfce7
BLAKE2b-256 b6003c9f1db367a5b8e5783aab84f2a1e72b48b3d7f7f943d5497f7c7569730c

See more details on using hashes here.

Provenance

The following attestation bundles were made for webimg_optimizer-0.1.0-py3-none-any.whl:

Publisher: workflow.yml on adewanggar/webimg-optimizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page