Skip to main content

A powerful image compression library with multiple algorithms and formats support

Project description

Re-pixel 🎨

PyPI version Python versions License: MIT

Re-pixel is a powerful and versatile Python library for image compression that supports multiple formats and algorithms. It provides both a simple Python API and a feature-rich command-line interface for compressing images while maintaining optimal quality.

✨ Features

  • Multiple Format Support: JPEG, PNG, WebP
  • Smart Compression: Automatic quality optimization for target file sizes
  • Batch Processing: Compress entire directories with progress tracking
  • Advanced Algorithms: Multiple compression techniques including lossless options
  • CLI Interface: Easy-to-use command-line tool with rich output
  • Flexible API: Simple Python API for integration into your projects
  • Image Analysis: Detailed image information and compression statistics
  • Resize & Compress: Automatic resizing with aspect ratio preservation

🚀 Installation

From PyPI (Recommended)

pip install re-pixel

From Source

git clone https://github.com/rakshithkalmadi/re-pixel.git
cd re-pixel
pip install -e .

Development Installation

git clone https://github.com/rakshithkalmadi/re-pixel.git
cd re-pixel
pip install -e ".[dev]"

📖 Quick Start

Python API

from repixel import ImageCompressor

# Initialize compressor
compressor = ImageCompressor()

# Compress a single image
result = compressor.compress(
    input_path="photo.jpg",
    output_path="photo_compressed.jpg",
    quality=80,
    format="jpeg"
)

print(f"Original size: {result['original_size_mb']:.2f} MB")
print(f"Compressed size: {result['compressed_size_mb']:.2f} MB")
print(f"Space saved: {result['space_saved_percent']:.1f}%")

# Batch compress all images in a directory
results = compressor.compress_batch(
    input_dir="photos/",
    output_dir="compressed_photos/",
    quality=85,
    format="webp",
    recursive=True
)

# Optimize quality for target file size
result = compressor.optimize_quality(
    input_path="large_photo.jpg",
    target_size_mb=2.0,
    format="jpeg"
)

Command-Line Interface

# Compress a single image
re-pixel compress photo.jpg -q 80 -f webp -o photo_compressed.webp

# Batch compress images in a directory
re-pixel batch photos/ -o compressed/ -q 85 -f webp --recursive

# Find optimal quality for target size
re-pixel optimize large_photo.jpg --target-size 2.0 -f jpeg -o optimized.jpg

# Get image information
re-pixel info photo.jpg

# List supported formats
re-pixel formats

🔧 Advanced Usage

Custom Compression Settings

from repixel import ImageCompressor

compressor = ImageCompressor()

# JPEG with progressive encoding
result = compressor.compress(
    input_path="photo.jpg",
    output_path="optimized.jpg",
    quality=90,
    format="jpeg",
    optimize=True,
    progressive=True
)

# WebP lossless compression
result = compressor.compress(
    input_path="graphic.png",
    output_path="graphic.webp",
    format="webp",
    lossless=True
)

# PNG with color reduction
result = compressor.compress(
    input_path="image.png",
    output_path="compressed.png",
    quality=70,  # Affects color palette reduction
    compress_level=9
)

Resize and Compress

from repixel.algorithms import AdvancedCompressor

# Resize to fit within bounds and compress
result = AdvancedCompressor.resize_and_compress(
    input_path="high_res.jpg",
    output_path="web_optimized.jpg",
    max_width=1920,
    max_height=1080,
    quality=85,
    format="jpeg"
)

Image Information

from repixel.utils import get_image_info, format_file_size

info = get_image_info("photo.jpg")
print(f"Dimensions: {info['dimensions']}")
print(f"File size: {format_file_size(info['size_bytes'])}")
print(f"Format: {info['format']}")
print(f"Megapixels: {info['megapixels']} MP")

🎛️ CLI Reference

Commands

  • compress - Compress a single image
  • batch - Compress multiple images in a directory
  • optimize - Find optimal quality for target file size
  • info - Display image information
  • formats - List supported formats

Common Options

  • -q, --quality - Compression quality (1-100)
  • -f, --format - Output format (jpeg, png, webp)
  • -o, --output - Output path
  • --optimize - Enable optimization
  • --progressive - Enable progressive JPEG
  • --lossless - Use lossless compression (WebP)
  • -v, --verbose - Verbose output

Examples

# High quality JPEG compression
re-pixel compress input.jpg -q 95 -f jpeg --progressive --optimize

# Batch convert to WebP with custom quality
re-pixel batch photos/ -o webp_photos/ -f webp -q 80 --recursive

# Optimize for web (target 500KB)
re-pixel optimize large.jpg --target-size 0.5 -f jpeg -o web_ready.jpg

# Get detailed image information
re-pixel info photo.jpg --verbose

📊 Format Comparison

Format Best For Compression Transparency Animation
JPEG Photos, complex images Lossy, high
PNG Graphics, simple images Lossless
WebP Web images, modern browsers Both

🎯 Quality Guidelines

  • 95-100: Maximum quality, minimal compression
  • 85-95: High quality, good for professional use
  • 75-85: Good quality, recommended for web
  • 65-75: Medium quality, smaller file sizes
  • 50-65: Lower quality, significant compression
  • Below 50: Poor quality, maximum compression

🛠️ Development

For comprehensive development instructions, including building, testing, and installation methods, see DEVELOPMENT.md.

Setup Development Environment

git clone https://github.com/rakshithkalmadi/re-pixel.git
cd re-pixel
pip install -e ".[dev]"

Run Tests

python -m pytest tests/ -v

Code Formatting

black repixel/
flake8 repixel/

Type Checking

mypy repixel/

📦 Building and Publishing

Build the Package

python -m build

Upload to PyPI

twine upload dist/*

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup

For detailed development instructions, see DEVELOPMENT.md.

Quick start:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Set up development environment (pip install -e ".[dev]")
  4. Run tests (python -m pytest tests/ -v)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

📄 License

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

🙏 Acknowledgments

  • Pillow for image processing capabilities
  • OpenCV for advanced image algorithms
  • Click for the CLI interface

📞 Support

If you encounter any issues or have questions:


Made with ❤️ by Rakshith Kalmadi

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

re_pixel-1.0.1.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

re_pixel-1.0.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file re_pixel-1.0.1.tar.gz.

File metadata

  • Download URL: re_pixel-1.0.1.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for re_pixel-1.0.1.tar.gz
Algorithm Hash digest
SHA256 77692d48c5c78d29aaf9c431ab2825692f44057b39884146342fd5a220a41c33
MD5 c3eb6082d1dafb89c65afd450d472dd5
BLAKE2b-256 0607a5bbb31d137be29cbd2ed20021c84822d628248a46a0fc07899c5c78d4fe

See more details on using hashes here.

File details

Details for the file re_pixel-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: re_pixel-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for re_pixel-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9883f1fa7ec77c2d6f1983745927f9800bc2c04e41f71c6bc6638304d1c36ce
MD5 1ba9bea3cd48e76b19b598542846c2d6
BLAKE2b-256 020f2fd3f4ec85470459f360cb6b80165a62fcf3fb16f639462bad7047ad467d

See more details on using hashes here.

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