A powerful image compression library with multiple algorithms and formats support
Project description
Re-pixel 🎨
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, BMP, TIFF
- 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 and sharpening
result = compressor.compress(
input_path="photo.jpg",
output_path="optimized.jpg",
quality=90,
format="jpeg",
optimize=True,
progressive=True,
enhance_sharpness=True,
sharpness_factor=1.2
)
# 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 imagebatch- Compress multiple images in a directoryoptimize- Find optimal quality for target file sizeinfo- Display image informationformats- 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
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.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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:
- 🐛 Report bugs
- 💡 Request features
- 📧 Contact: your.email@example.com
Made with ❤️ by Rakshith Kalmadi
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 re_pixel-1.0.0.tar.gz.
File metadata
- Download URL: re_pixel-1.0.0.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51562d8f19c7ba19fbd38c8ec8165cad128d55d5a661feceac29fcd8504e3888
|
|
| MD5 |
bfadd9161659e0d21e33ce27407c82a9
|
|
| BLAKE2b-256 |
5744d137705ff86625f50a0f9cdf2c6e357bdc810372501ee406517f9aef4b53
|
File details
Details for the file re_pixel-1.0.0-py3-none-any.whl.
File metadata
- Download URL: re_pixel-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
929bf3803c566ce24346fb89c96988caf4740f4f8e6fbea5ca2062cd38b02f64
|
|
| MD5 |
4ec33a1c98776995b395ab1ebd4f861e
|
|
| BLAKE2b-256 |
6e96d147fee17c5f4cd4b1d0a23f7845a5cbec7e7ea13f9ea234a77561cdb212
|