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
✨ 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
img = imgrs.open("photo.jpg")
resized = img.resize((800, 600))
cropped = img.crop((100, 100, 500, 400))
rotated = img.rotate(90)
img.save("output.png")
img.show()
new_img = imgrs.new("RGB", (800, 600), "red")
gray_img = img.convert("L")
rgba_img = img.convert("RGBA")
r, g, b = img.split()
base = imgrs.new("RGB", (200, 200), "white")
overlay = imgrs.new("RGB", (100, 100), "red")
result = base.paste(overlay, (50, 50))
import numpy as np
array = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
img_from_array = imgrs.fromarray(array)
blurred = img.blur(2.0)
sharpened = img.sharpen(1.5)
sepia_tone = img.sepia()
pixel_color = img.getpixel((50, 50))
img.putpixel((50, 50), (255, 0, 0, 255))
histogram = img.histogram()
dominant = img.dominant_color()
average = img.average_color()
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))
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
from imgrs import Image
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 radius
sharpen() - Sharpening filter with adjustable strength
edge_detect() - Edge detection using Sobel operator
emboss() - Emboss effect
brightness() - Brightness adjustment
contrast() - Contrast adjustment
CSS-like Filters:
sepia() - Sepia tone effect
grayscale_filter() - Grayscale conversion with amount control
invert() - Color inversion effect
hue_rotate() - Hue rotation in degrees
saturate() - Saturation adjustment
Filter chaining - Combine multiple filters for complex effects
🎯 Pixel Manipulation - NEW!
getpixel(), putpixel() - Direct pixel access and modification
histogram() - Color histogram analysis
dominant_color(), average_color() - Color analysis
replace_color() - Color replacement with tolerance
threshold() - Binary thresholding
posterize() - Color quantization
🎨 Drawing Operations - NEW!
draw_rectangle() - Filled rectangles with alpha blending
draw_circle() - Filled circles with alpha blending
draw_line() - Lines using Bresenham's algorithm
- Shape generation:
circle(), rectangle(), triangle(), ellipse(), star(), etc.
📝 Text Rendering - NEW!
add_text() - Basic text rendering with flexible positioning
add_text_styled() - Styled text with outlines, shadows, backgrounds, and opacity
add_text_multiline() - Multi-line text with alignment and custom line spacing
add_text_centered() - Horizontally centered text rendering
get_text_dimensions() - Text size and metrics calculation
get_multiline_text_dimensions() - Multi-line text dimensions with line count
get_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 files
ImageFont.truetype() - Load TrueType fonts (Pillow-compatible)
ImageFont.load_default() - Get default fallback font
ImageFont.get_font() - Get font with automatic fallback
text() - Pillow-compatible text drawing method
✨ Shadow Effects - NEW!
drop_shadow() - Drop shadow with blur and offset
inner_shadow() - Inner shadow effects
glow() - 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
img = imgrs.open("path/to/image.jpg")
img = imgrs.open(image_bytes)
img = imgrs.new(mode, size, color=None)
img = imgrs.new("RGB", (800, 600))
img = imgrs.new("RGB", (800, 600), "red")
img = imgrs.new("RGB", (800, 600), (255, 0, 0))
Image Operations
resized = img.resize((width, height), resample=imgrs.Resampling.BILINEAR)
cropped = img.crop((x1, y1, x2, y2))
rotated = img.rotate(90)
flipped = img.transpose(imgrs.Transpose.FLIP_LEFT_RIGHT)
flipped = img.transpose(imgrs.Transpose.FLIP_TOP_BOTTOM)
copy = img.copy()
img.thumbnail((200, 200))
img.save("output.jpg", format="JPEG")
img.save("output.png")
img.show()
Properties
width = img.width
height = img.height
size = img.size
mode = img.mode
format = img.format
bytes_data = img.to_bytes()
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))
img.add_text_styled(
"Styled Text",
(x, y),
size=28,
color=(255, 255, 255, 255),
outline=(0, 0, 0, 255, 2.0),
shadow=(3, 3, 128, 128, 128, 200),
background=(100, 149, 237, 255),
opacity=0.9
)
img.add_text_multiline(
"Line 1\nLine 2\nLine 3",
(x, y),
size=20,
color=(0, 0, 0, 255),
align="center",
line_spacing=1.5
)
img.add_text_centered("Centered Text", y, size=32, color=(0, 0, 0, 255))
width, height, ascent, descent = img.get_text_dimensions("Text", 24)
bbox = img.get_text_bounding_box("Text", x, y, 24)
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
git clone https://github.com/grandpaej/imgrs.git
cd imgrs
pip install -r requirements.txt
maturin develop --release
pytest python/imgrs/tests/
Requirements
- Python 3.8+
- Rust 1.70+
- Maturin for building
📖 Learn More
🚀 Getting Started
📚 Reference & Examples
🎯 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
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