png-resizer

Crates.iopng-resizer
lib.rspng-resizer
version1.0.0
created_at2026-01-12 07:23:51.461247+00
updated_at2026-01-12 07:23:51.461247+00
descriptionHigh-performance PNG image resizer built with Rust and fast_image_resize library
homepagehttps://github.com/cumulus13/png-resizer
repositoryhttps://github.com/cumulus13/png-resizer
max_upload_size
id2037190
size47,701
cumulus13 (cumulus13)

documentation

https://docs.rs/png-resizer

README

png-resizer

Crates.io Documentation License: MIT

High-performance PNG image resizer built with Rust and the fast_image_resize library.

Features

  • Blazing Fast: Uses SIMD instructions (AVX2, SSE4.1, NEON) + multithreading via Rayon
  • 🎨 High Quality: Proper sRGB ↔ linear RGB color space conversion for accurate resizing
  • 📦 Zero Dependencies: No external C libraries required (unlike libvips-based tools)
  • 🔧 Easy to Use: Simple CLI interface with automatic aspect ratio preservation
  • 💾 Memory Efficient: Optimized for processing large images

Installation

From crates.io

cargo install png-resizer

From source

git clone https://github.com/cumulus13/png-resizer
cd png-resizer
cargo build --release

Binary will be at ./target/release/png-resizer

Usage

Basic Usage (maintains aspect ratio automatically)

png-resizer input.png --width 800 -o output.png

Specify both width and height

png-resizer input.png --width 800 --height 600 -o output.png

Choose resize algorithm

# Fastest (lower quality)
png-resizer input.png -w 800 -o output.png -a nearest

# High quality (default)
png-resizer input.png -w 800 -o output.png -a lanczos3

Disable multithreading

png-resizer input.png -w 800 -o output.png --no-threads

Command Line Arguments

Usage: png-resizer [OPTIONS] <INPUT> --output <OUTPUT> --width <WIDTH>

Arguments:
  <INPUT>  Input PNG file path

Options:
  -o, --output <OUTPUT>        Output PNG file path
  -w, --width <WIDTH>          Target width (pixels)
      --height <HEIGHT>        Target height (pixels). If not specified, maintains aspect ratio
  -a, --algorithm <ALGORITHM>  Resize algorithm [default: lanczos3] [possible values: nearest, bilinear, catmull, mitchell, lanczos3]
      --no-threads             Disable multithreading
  -v, --version                Show version information
  -h, --help                   Print help

Resize Algorithms

Algorithm Speed Quality Best For
nearest ⚡⚡⚡⚡⚡ Pixel art, extremely fast preview
bilinear ⚡⚡⚡⚡ ⭐⭐⭐ General use, good speed/quality balance
catmull ⚡⚡⚡ ⭐⭐⭐⭐ Smooth edges, natural looking
mitchell ⚡⚡⭐ ⭐⭐⭐⭐ Balanced sharpness and smoothness
lanczos3 ⚡⚡ ⭐⭐⭐⭐⭐ Best quality (default, recommended)

Examples

Resize maintaining aspect ratio

png-resizer photo.png -w 1920 -o photo_resized.png

Create thumbnail

png-resizer large_image.png -w 300 -o thumbnail.png

Batch processing

# Bash/Linux
for file in *.png; do
    png-resizer "$file" -w 800 -o "resized_$file"
done

# PowerShell
Get-ChildItem *.png | ForEach-Object {
    png-resizer $_.Name -w 800 -o "resized_$($_.Name)"
}

Different quality levels

# Maximum quality (slower)
png-resizer input.png -w 1200 -o high_quality.png -a lanczos3

# Fast processing (lower quality)
png-resizer input.png -w 1200 -o fast.png -a bilinear

Performance

This tool uses fast_image_resize, which is one of the fastest image resizing libraries available:

  • vs ImageMagick: ~3-5x faster
  • vs Pillow (Python): ~4-6x faster
  • vs Go standard library: ~2-3x faster

Performance comes from:

  • SIMD vectorization (processes multiple pixels simultaneously)
  • Multi-core utilization via Rayon
  • Optimized memory access patterns
  • Zero-copy operations where possible

Technical Details

Why fast_image_resize?

fast_image_resize provides:

  • Proper color space handling (sRGB ↔ linear RGB conversion)
  • Multiple high-quality resize algorithms
  • SIMD support for x86-64 (AVX2, SSE4.1) and ARM (NEON)
  • Thread-safe parallel processing
  • No external C library dependencies

Aspect Ratio Preservation

When --height is not specified, the tool automatically calculates the height to maintain the original image's aspect ratio:

new_height = original_height × (new_width / original_width)

Alternative Tools

If you need additional features, consider:

  • Rimage: Full-featured image optimization CLI (also uses fast_image_resize)
  • ImageMagick: Feature-rich but slower
  • libvips: Fast but requires C library installation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

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

👤 Author

Hadi Cahyadi

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon

Acknowledgments

See Also

Commit count: 1

cargo fmt