Skip to main content

CLI tool to square images for web with smart padding

Project description

webimg-square

CLI tool to square images for web with smart padding.

Features

  • Smart squaring: Adds padding to make images square using the larger dimension
  • Auto background detection: Analyzes image corners to determine padding color
  • Intelligent resizing: Only shrinks images larger than 2500px (configurable)
  • Transparency support: Preserves PNG transparency with transparent padding
  • AVIF conversion: Automatically converts AVIF files to PNG
  • Batch processing: Process entire directories recursively
  • Dry-run mode: Preview changes before applying

Installation

pip install webimg-square

Usage

Basic usage

# Process a single image
webimg-square image.jpg

# Process a directory recursively
webimg-square ./photos/

# Process multiple paths
webimg-square image1.jpg image2.png ./more-photos/

Options

# Custom maximum size (default: 2500)
webimg-square --max-size 1500 ./photos/

# Preview changes without modifying files
webimg-square --dry-run ./photos/

# Non-recursive directory processing
webimg-square --no-recursive ./photos/

# Verbose output
webimg-square -v ./photos/

Processing Rules

  1. Already square images: Skipped (no changes)
  2. Non-square images: Padded to square using the larger dimension
  3. Large images (>2500px): Resized to 2500px max, then squared
  4. Small images (<2500px): Only squared, never upscaled
  5. Transparent PNGs: Use transparent padding
  6. AVIF files: Converted to PNG

Supported Formats

Format Read Write Notes
JPEG Quality 95
PNG Transparency preserved
WebP Quality 95
AVIF → PNG Converted to PNG
GIF First frame only
BMP
TIFF

Examples

Landscape image (1000x500)

  • Result: 1000x1000 with 250px padding top and bottom

Portrait image (500x1000)

  • Result: 1000x1000 with 250px padding left and right

Large image (3000x4000)

  • Resized to 1875x2500 (maintaining aspect ratio)
  • Result: 2500x2500 with padding

Small image (100x200)

  • Result: 200x200 (not upscaled to 2500)

Development

# Setup
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=webimg_square

License

MIT

Project details


Download files

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

Source Distribution

webimg_square-1.0.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

webimg_square-1.0.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file webimg_square-1.0.0.tar.gz.

File metadata

  • Download URL: webimg_square-1.0.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for webimg_square-1.0.0.tar.gz
Algorithm Hash digest
SHA256 936a8fc952405e65f75ce78cc5949fd400a7d1481400ac176c908b730be9c0ba
MD5 4ec6a1aa59c0b21f33becc4dab490d9d
BLAKE2b-256 7befc82ebeff52510674331889e8cf0d1c1df1dd9c07e65a13cce660d8b6a51b

See more details on using hashes here.

Provenance

The following attestation bundles were made for webimg_square-1.0.0.tar.gz:

Publisher: publish.yml on iamrusak/webimg-square

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_square-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: webimg_square-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for webimg_square-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3a653592883b28dbe1972e94d1ef309b4e510f21500c9dac99d322e58c61fa0
MD5 218178914c891430b71f7b074c5caccc
BLAKE2b-256 f9c6650e12770f934adc49d7be8c20235ed484288e59e63d8c028d31d9a2a654

See more details on using hashes here.

Provenance

The following attestation bundles were made for webimg_square-1.0.0-py3-none-any.whl:

Publisher: publish.yml on iamrusak/webimg-square

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

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