Imgrs 🦀
Version 0.3.1 - Advanced text rendering has been re-added through the new TextMixin system, providing comprehensive text operations without external dependencies.
Imgrs is a blazingly fast, modern image processing library for Python, powered by Rust. Imgrs provides a Pillow-compatible API while delivering significantly better performance for common image operations.
📚 Documentation
- Quick Start Guide - Get up and running in minutes
- Basic Usage - Core concepts and common patterns
- API Reference - Complete method documentation
- Examples - Real-world usage examples
- Migration Guide - Migrating from Pillow
✨ Key Features
- 🔥 High Performance: Significantly fast for common image operations
- 🔄 Pillow Compatible: Drop-in replacement for most Pillow operations
- 🦀 Rust Powered: Memory-safe and efficient core written in Rust
- 📦 Easy to Use: Simple, intuitive API that feels familiar
- 🎯 Format Support: PNG, JPEG, BMP, TIFF, GIF, WEBP
- 🎨 65+ Filters: Comprehensive filter library (blur, sharpen, artistic effects)
- 🔧 Pixel Operations: Direct pixel manipulation and analysis
- 🎭 Drawing Tools: Shapes, lines, and advanced drawing operations
- 📝 Text Rendering: Advanced text operations with styling and effects - NEW!
- ⚡ Auto-Enhancement: Smart image optimization and color correction
🚀 Quick Start
Imgrs Installation
pip install imgrs
Basic Usage
import imgrs
# Open an image
img = imgrs.open("photo.jpg")
# Resize image
resized = img.resize((800, 600))
# Crop image
cropped = img.crop((100, 100, 500, 400))
# Rotate image
rotated = img.rotate(90)
# Save image
img.save("output.png")
# to preview
img.show()
# Create new image
new_img = imgrs.new("RGB", (800, 600), "red")
# Convert image modes
gray_img = img.convert("L") # RGB to grayscale
rgba_img = img.convert("RGBA") # Add alpha channel
# Split image into channels
r, g, b = img.split() # RGB image -> 3 grayscale images
# Paste one image onto another
base = imgrs.new("RGB", (200, 200), "white")
overlay = imgrs.new("RGB", (100, 100), "red")
result = base.paste(overlay, (50, 50)) # Paste at position (50, 50)
# Create image from NumPy array (requires numpy)
import numpy as np
array = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
img_from_array = imgrs.fromarray(array)
# Apply filters for image enhancement
blurred = img.blur(2.0)
sharpened = img.sharpen(1.5)
sepia_tone = img.sepia()
# Pixel manipulation
pixel_color = img.getpixel((50, 50))
img.putpixel((50, 50), (255, 0, 0, 255))
# Color analysis
histogram = img.histogram()
dominant = img.dominant_color()
average = img.average_color()
# Drawing operations
img.draw_rectangle(10, 10, 100, 100, (255, 0, 0, 128))
img.draw_circle(150, 150, 50, (0, 255, 0, 128))
img.draw_line(0, 0, 200, 200, (0, 0, 255, 255))
# Text rendering
img.add_text("Hello World!", (20, 20), size=32, color=(0, 0, 0, 255))
img.add_text_styled("Styled Text", (20, 60), size=24, color=(255, 255, 255, 255),
outline=(0, 0, 0, 255, 1.0), background=(100, 149, 237, 255))
img.add_text_multiline("Multi-line\ntext example", (20, 100), size=18, color=(0, 100, 0, 255))
Drop-in Pillow Replacement
# Replace this:
# from PIL import Image
# With this:
from imgrs import Image
# Your existing Pillow code works unchanged!
img = Image.open("photo.jpg")
img = img.resize((400, 300))
img.save("resized.jpg")
🔄 Pillow Compatibility
✅ Fully Compatible Operations
open(),new(),save()resize(),crop(),rotate(),transpose()copy(),thumbnail()convert(),paste(),split()- NEW!fromarray()- NEW! NumPy Integration- Properties:
size,width,height,mode,format - All major image formats (PNG, JPEG, BMP, TIFF, GIF, WEBP)
🎨 Image Filters - NEW!
Basic Filters:
blur()- Gaussian blur with adjustable radiussharpen()- Sharpening filter with adjustable strengthedge_detect()- Edge detection using Sobel operatoremboss()- Emboss effectbrightness()- Brightness adjustmentcontrast()- Contrast adjustment
CSS-like Filters:
sepia()- Sepia tone effectgrayscale_filter()- Grayscale conversion with amount controlinvert()- Color inversion effecthue_rotate()- Hue rotation in degreessaturate()- Saturation adjustment
Filter chaining - Combine multiple filters for complex effects
🎯 Pixel Manipulation - NEW!
getpixel(),putpixel()- Direct pixel access and modificationhistogram()- Color histogram analysisdominant_color(),average_color()- Color analysisreplace_color()- Color replacement with tolerancethreshold()- Binary thresholdingposterize()- Color quantization
🎨 Drawing Operations - NEW!
draw_rectangle()- Filled rectangles with alpha blendingdraw_circle()- Filled circles with alpha blendingdraw_line()- Lines using Bresenham's algorithm- Shape generation:
circle(),rectangle(),triangle(),ellipse(),star(), etc.
📝 Text Rendering - NEW!
add_text()- Basic text rendering with flexible positioningadd_text_styled()- Styled text with outlines, shadows, backgrounds, and opacityadd_text_multiline()- Multi-line text with alignment and custom line spacingadd_text_centered()- Horizontally centered text renderingget_text_dimensions()- Text size and metrics calculationget_multiline_text_dimensions()- Multi-line text dimensions with line countget_text_bounding_box()- Complete text bounding box with ascent/descent/baseline- Convenience methods:
add_text_with_shadow(),add_text_with_outline(),add_text_with_background()
🔤 Font Support - NEW!
ImageFont.load()- Load TTF, OTF, WOFF, WOFF2 font filesImageFont.truetype()- Load TrueType fonts (Pillow-compatible)ImageFont.load_default()- Get default fallback fontImageFont.get_font()- Get font with automatic fallbacktext()- Pillow-compatible text drawing method
✨ Shadow Effects - NEW!
drop_shadow()- Drop shadow with blur and offsetinner_shadow()- Inner shadow effectsglow()- Glow effects with customizable intensity
🚧 Planned Features
frombytes(),tobytes()- Enhanced I/O- Path operations and vector graphics
- Additional blend modes and compositing operations
- Arbitrary angle rotation support
📖 API Reference
Core Functions
# Open image from file or bytes
img = imgrs.open("path/to/image.jpg")
img = imgrs.open(image_bytes)
# Create new image
img = imgrs.new(mode, size, color=None)
# Examples:
img = imgrs.new("RGB", (800, 600)) # Black image
img = imgrs.new("RGB", (800, 600), "red") # Red image
img = imgrs.new("RGB", (800, 600), (255, 0, 0)) # Red image with RGB tuple
Image Operations
# Resize image
resized = img.resize((width, height), resample=imgrs.Resampling.BILINEAR)
# Crop image (left, top, right, bottom)
cropped = img.crop((x1, y1, x2, y2))
# Rotate image (90°, 180°, 270° supported)
rotated = img.rotate(90)
# Transpose/flip image
flipped = img.transpose(imgrs.Transpose.FLIP_LEFT_RIGHT)
flipped = img.transpose(imgrs.Transpose.FLIP_TOP_BOTTOM)
# Copy image
copy = img.copy()
# Create thumbnail (modifies image in-place)
img.thumbnail((200, 200))
# Save image
img.save("output.jpg", format="JPEG")
img.save("output.png") # Format auto-detected from extension
img.show() # to preview
Properties
# Image dimensions
width = img.width
height = img.height
size = img.size # (width, height) tuple
# Image mode and format
mode = img.mode # "RGB", "RGBA", "L", etc.
format = img.format # "JPEG", "PNG", etc.
# Raw pixel data
bytes_data = img.to_bytes()
Text Rendering
# Basic text rendering
img.add_text("Hello World!", (x, y), size=32, color=(0, 0, 0, 255))
img.add_text("Text", x, y, size=24, color=(255, 0, 0, 255)) # Separate x,y
# Styled text with effects
img.add_text_styled(
"Styled Text",
(x, y),
size=28,
color=(255, 255, 255, 255),
outline=(0, 0, 0, 255, 2.0), # Black outline, 2px width
shadow=(3, 3, 128, 128, 128, 200), # Gray shadow, offset by 3px
background=(100, 149, 237, 255), # Blue background
opacity=0.9
)
# Multi-line text
img.add_text_multiline(
"Line 1\nLine 2\nLine 3",
(x, y),
size=20,
color=(0, 0, 0, 255),
align="center", # "left", "center", or "right"
line_spacing=1.5 # Line spacing multiplier
)
# Centered text
img.add_text_centered("Centered Text", y, size=32, color=(0, 0, 0, 255))
# Text measurement
width, height, ascent, descent = img.get_text_dimensions("Text", 24)
bbox = img.get_text_bounding_box("Text", x, y, 24) # Returns dict with box info
# Convenience methods
img.add_text_with_shadow("Shadow Text", (x, y), size=24, color=(255, 0, 0, 255),
shadow_color=(0, 0, 0, 180), shadow_offset=(2, 2))
img.add_text_with_outline("Outlined", (x, y), size=20, color=(255, 255, 0, 255),
outline_color=(0, 0, 0, 255), outline_width=1.5)
🔧 Development
Building from Source
# Clone repository
git clone https://github.com/grandpaej/imgrs.git
cd imgrs
# Install dependencies
pip install -r requirements.txt
# Build Rust extension
maturin develop --release
# Run tests
pytest python/imgrs/tests/
Requirements
- Python 3.8+
- Rust 1.70+
- Maturin for building
📖 Learn More
🚀 Getting Started
- Quick Start Guide - Installation and first steps
- Basic Usage - Essential concepts and patterns
📚 Reference & Examples
- API Reference - Complete method documentation
- Examples - Real-world usage examples
- Performance Guide - Optimization techniques
🎯 Use Cases
- Photography: Portrait enhancement, landscape processing, batch operations
- Web Development: Image resizing, format optimization, thumbnail generation
- Creative Projects: Artistic filters, collages, social media content
- Data Visualization: Charts, infographics, dashboard creation
- E-commerce: Product showcases, catalog generation, watermarking
🤝 Contributing
Contributors
- GrandpaEJ - Feature requests and guidance
- Bilal Tonga - Initial implementation of the project
How to Contribute
Contributions are welcome! Areas where help is needed:
- Medium Priority Features:
frombytes(),tobytes(), arbitrary angle rotation - Performance Optimization: Further speed improvements and benchmarking
- Format Support: Additional image formats and metadata handling
- Advanced Operations: Path operations, vector graphics, additional blend modes
- Documentation: More examples and tutorials
- Testing: Edge cases, compatibility tests, and performance benchmarks
📄 License
Apache Software License - see LICENSE file for details.
🙏 Acknowledgments
- Built with PyO3 for Python-Rust integration
- Uses image-rs for core image processing
- Inspired by Pillow for API design
- First Skaliton by Bilal Tonga
Metadata
Release files for imgrs 0.3.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| imgrs-0.3.8.tar.gz | 19.6 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| imgrs-0.3.8-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | PyPy 3.10 | PyPy 3.10 7.3 | Linux glibc 2.17+ ARM64 | Details |
| imgrs-0.3.8-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | PyPy 3.9 | PyPy 3.9 7.3 | Linux glibc 2.17+ ARM64 | Details |
| imgrs-0.3.8-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details |
| imgrs-0.3.8-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| imgrs-0.3.8-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| imgrs-0.3.8-cp38-abi3-macosx_11_0_arm64.whl | CPython 3.8 | abi3 | macOS 11.0+ ARM64 | Details |
| imgrs-0.3.8-cp38-abi3-macosx_10_12_x86_64.whl | CPython 3.8 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 46.4 MB
Release files / imgrs-0.3.8.tar.gz
| Download URL | imgrs-0.3.8.tar.gz |
|---|---|
| Size | 19.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee496c8b03d8d29ca5c584071127cdc3447c65e61a35c1cb1a392d55a3e95d97
|
|
BLAKE2b-256 checksum How to use checksums |
322a5bfee9e65d8f748b036a29c32f9abd60e47eaef3729964df24decf45a390
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / imgrs-0.3.8-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | imgrs-0.3.8-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | Linux glibc 2.17+ ARM64 PyPy 3.10 PyPy 3.10 7.3 |
|
SHA-256 checksum How to use checksums |
5e43b8c352731c10de2e7121f72631f64300d7f794b7f3ee2de76fe97724fbce
|
|
BLAKE2b-256 checksum How to use checksums |
b6ae2508f793567e51d163a7f75351a1ba9b6f11d1d9ad856099bd2fe29899f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / imgrs-0.3.8-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | imgrs-0.3.8-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | Linux glibc 2.17+ ARM64 PyPy 3.9 PyPy 3.9 7.3 |
|
SHA-256 checksum How to use checksums |
4a602fa5387dbb2ed2ce33d725fc49f853b596d472000bdd857166a3c1b5fbd5
|
|
BLAKE2b-256 checksum How to use checksums |
8f3b2e5cbda928c6916dc1113828603984474acd8e90fa7a0d58f7c8dfa0d3e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / imgrs-0.3.8-cp38-abi3-win_amd64.whl
| Download URL | imgrs-0.3.8-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 3.9 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
cb73182e1f4c5f1d8bab7c14f91b48ad1dd9cee304578f561e9d55bcfbc690e1
|
|
BLAKE2b-256 checksum How to use checksums |
f989500a8217025b6b326ea579059082c3096ab234286199779b38f49ddf7673
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / imgrs-0.3.8-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | imgrs-0.3.8-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
746174e53e38da403e91f7bbb8d127f60d79fb1985786ba28ebdeda9f9052761
|
|
BLAKE2b-256 checksum How to use checksums |
8f0040e580ff2dc75876afd1daa53f63e254005b7085690ef34f3a640843b3ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / imgrs-0.3.8-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | imgrs-0.3.8-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
cbdbbfb0bdd268c231eca9894a3d4f29c573aaf5c808d08cdc64ffa735c8c7a5
|
|
BLAKE2b-256 checksum How to use checksums |
92a647af2ae05c2351fc328e6aaacce728d5494dc018b54ee6e466b99b754ff1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / imgrs-0.3.8-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | imgrs-0.3.8-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
76fb4899e2e6ecdd5c6ef2234a862450130a7e7077a3eb66c3ee5e2a89131b47
|
|
BLAKE2b-256 checksum How to use checksums |
5f5de84ec955819da2574c989bd0aca5444440a15d44f0a135c08fd4fb79b009
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / imgrs-0.3.8-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | imgrs-0.3.8-cp38-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.8 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
6fdfee1b054c45de635ea81bca1009211e8eab2daf8d13d2144f53c76423d772
|
|
BLAKE2b-256 checksum How to use checksums |
fa59e6856956983f776ec3082c882c339f6a5cfcd436ec6efda11483cbe28f99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|