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
- Already square images: Skipped (no changes)
- Non-square images: Padded to square using the larger dimension
- Large images (>2500px): Resized to 2500px max, then squared
- Small images (<2500px): Only squared, never upscaled
- Transparent PNGs: Use transparent padding
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
936a8fc952405e65f75ce78cc5949fd400a7d1481400ac176c908b730be9c0ba
|
|
| MD5 |
4ec6a1aa59c0b21f33becc4dab490d9d
|
|
| BLAKE2b-256 |
7befc82ebeff52510674331889e8cf0d1c1df1dd9c07e65a13cce660d8b6a51b
|
Provenance
The following attestation bundles were made for webimg_square-1.0.0.tar.gz:
Publisher:
publish.yml on iamrusak/webimg-square
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webimg_square-1.0.0.tar.gz -
Subject digest:
936a8fc952405e65f75ce78cc5949fd400a7d1481400ac176c908b730be9c0ba - Sigstore transparency entry: 872123501
- Sigstore integration time:
-
Permalink:
iamrusak/webimg-square@210da1141c41789b32d8049719898bfa801da49e -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/iamrusak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@210da1141c41789b32d8049719898bfa801da49e -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3a653592883b28dbe1972e94d1ef309b4e510f21500c9dac99d322e58c61fa0
|
|
| MD5 |
218178914c891430b71f7b074c5caccc
|
|
| BLAKE2b-256 |
f9c6650e12770f934adc49d7be8c20235ed484288e59e63d8c028d31d9a2a654
|
Provenance
The following attestation bundles were made for webimg_square-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on iamrusak/webimg-square
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webimg_square-1.0.0-py3-none-any.whl -
Subject digest:
f3a653592883b28dbe1972e94d1ef309b4e510f21500c9dac99d322e58c61fa0 - Sigstore transparency entry: 872123502
- Sigstore integration time:
-
Permalink:
iamrusak/webimg-square@210da1141c41789b32d8049719898bfa801da49e -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/iamrusak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@210da1141c41789b32d8049719898bfa801da49e -
Trigger Event:
push
-
Statement type: