Fast image conversion library with exceptional SVG support
Project description
imgshift
Shift between any image format effortlessly.
A high-performance Python library for universal image format conversion with exceptional SVG support. Features dual-engine SVG rendering (production-grade resvg + pure-Python fallback) and supports all major image formats.
Features
- 🎨 Universal Format Support: Convert between PNG, JPEG, WebP, GIF, BMP, TIFF, ICO, SVG, and PDF
- � Dual-Engine SVG Rendering: Production-grade
resvgengine with pure-Python fallback - 🔧 Flexible Engine Selection: Choose between
auto(smart fallback),resvg(production), orpython(experimental) - 📐 Smart Upscaling: Lanczos/bicubic/bilinear interpolation for high-quality image scaling
- 📄 PDF Support: Convert images to/from PDF, combine multiple images into multi-page PDFs
- 🔧 Flexible API: Simple one-liner functions or fluent method chaining
- 💻 CLI Tool: Command-line interface with engine selection support
Installation
pip install imgshift
This installs all dependencies including resvg-py for production-grade SVG rendering.
Quick Start
Simple Conversion
from imgshift import convert
# SVG to PNG (uses best available engine)
convert("icon.svg", "icon.png")
# With specific size
convert("icon.svg", "icon.png", width=512)
# Use specific SVG engine
convert("logo.svg", "logo.png", engine="resvg") # Production quality
convert("simple.svg", "simple.png", engine="python") # Zero dependencies
# PNG to JPEG with quality
convert("photo.png", "photo.jpg", quality=90)
# PDF page to PNG
convert("document.pdf", "page.png", page=0, dpi=300)
Fluent API
from imgshift import Image
# Chain operations
Image("icon.svg").resize(512, 512).save("icon.png")
# With quality and DPI settings
Image("photo.png").set_quality(95).set_dpi(150).save("photo.jpg")
# PDF with specific page
Image("document.pdf").page(0).set_dpi(300).save("page.png")
Multiple Images to PDF
from imgshift import convert
# Combine multiple images into a PDF
convert(["page1.png", "page2.png", "page3.png"], "document.pdf")
CLI Usage
# Single file conversion
imgshift input.svg output.png
# With options
imgshift input.svg output.png --width 512 --height 512
# Choose SVG engine
imgshift logo.svg logo.png --engine resvg # Production quality
imgshift icon.svg icon.png --engine python # Pure Python
# Batch conversion
imgshift *.svg --to png --output-dir ./converted
# Multiple files to PDF
imgshift img1.png img2.png img3.png -o output.pdf
CLI Options
| Option | Description |
|---|---|
--width, -w |
Output width in pixels |
--height, -H |
Output height in pixels |
--quality, -q |
JPEG/WebP quality (1-100, default: 85) |
--dpi, -d |
DPI for PDF/SVG rendering (default: 150) |
--page, -p |
PDF page number (0-indexed) |
--engine |
SVG engine: auto, resvg, or python |
--to, -t |
Target format for batch conversion |
--output-dir, -o |
Output directory |
Supported Formats
| Format | Read | Write | Notes |
|---|---|---|---|
| PNG | ✅ | ✅ | Lossless with alpha channel |
| JPEG | ✅ | ✅ | Lossy compression, quality 1-100 |
| WebP | ✅ | ✅ | Modern format, lossy/lossless |
| GIF | ✅ | ✅ | Palette-based, 256 colors |
| BMP | ✅ | ✅ | Uncompressed bitmap |
| TIFF | ✅ | ✅ | High-quality, supports compression |
| ICO | ✅ | ✅ | Windows icon format |
| SVG | ✅ | ❌ | Vector graphics (custom renderer) |
| ✅ | ✅ | Single or multi-page documents |
SVG Rendering
imgshift uses a dual-engine architecture for SVG rendering:
Primary Engine: resvg (Production)
The resvg engine (installed by default) provides:
- ✅ Full SVG 1.1 specification compliance
- ✅ Complex gradients, patterns, and filters
- ✅ Advanced path operations and clipping
- ✅ Production-grade accuracy (used by major tools)
- ✅ Rust-powered performance
Default: Used automatically for best quality.
Fallback Engine: python (Experimental)
The pure-Python engine provides:
- ✅ Zero external dependencies (if you uninstall resvg-py)
- ✅ Basic SVG shapes and paths
- ✅ Transforms and styling
- ⚠️ Limited support for advanced features
- ⚠️ May have rendering artifacts on complex SVGs
Use when: You need to avoid compiled dependencies or rendering very simple SVGs.
Engine Selection
# Auto mode (default): tries resvg, falls back to python
convert("logo.svg", "logo.png", engine="auto")
# Explicit resvg (production)
convert("complex.svg", "complex.png", engine="resvg")
# Explicit python (zero dependencies)
convert("simple.svg", "simple.png", engine="python")
Default behavior: resvg is used automatically. You can explicitly choose the pure-Python engine if needed.
Supported SVG Features
Python Engine Support
Shapes
<rect>- Rectangles (including rounded corners)<circle>- Circles<ellipse>- Ellipses<line>- Lines<polyline>- Connected line segments<polygon>- Closed polygons<path>- Full path syntax including curves<text>- Basic text rendering
Path Commands
- Move:
M,m - Line:
L,l,H,h,V,v - Cubic Bezier:
C,c,S,s - Quadratic Bezier:
Q,q,T,t - Arc:
A,a - Close:
Z,z
Styling
fill- Fill color (hex, named colors, rgb/rgba)stroke- Stroke colorstroke-width- Stroke widthopacity- Element opacityfill-opacity- Fill opacitystroke-opacity- Stroke opacity
Transforms
translate(x, y)rotate(angle)orrotate(angle, cx, cy)scale(x)orscale(x, y)skewX(angle)/skewY(angle)matrix(a, b, c, d, e, f)
API Reference
convert(source, target, **options)
Convert an image from one format to another.
Parameters:
source: Source file path (str or Path), or list of paths for multi-image PDFtarget: Target file pathwidth: Target width (optional)height: Target height (optional)quality: JPEG/WebP quality 1-100 (default: 85)dpi: DPI for PDF/SVG rendering (default: 150)page: PDF page number, 0-indexed (optional)background: Background color tuple (R, G, B, A) for SVG (default: white)engine: SVG rendering engine:"auto","resvg", or"python"(default:"auto")
Image(source)
Fluent API for image manipulation.
Methods:
.resize(width, height)- Set target dimensions.set_quality(quality)- Set JPEG/WebP quality.set_dpi(dpi)- Set DPI for PDF/SVG.page(page_num)- Select PDF page.set_background(r, g, b, a)- Set SVG background color.save(dest)- Save to file
Dependencies
- pypng - Pure Python PNG handling
- Pillow - JPEG and other raster formats
- PyMuPDF - PDF reading and writing
- resvg-py - Production-grade SVG rendering
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
Built with ❤️ for the Python community.
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 imgshift-0.1.2.tar.gz.
File metadata
- Download URL: imgshift-0.1.2.tar.gz
- Upload date:
- Size: 56.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fe0d6dc5bdcb2adfd7dec82c4b5e497cd2d875dba831b3dd248dbc93d2e8d5d
|
|
| MD5 |
84f3640435513d8e9ae8f6687b6f66d9
|
|
| BLAKE2b-256 |
f7ae8c8336a25b832e0ec551a4bdfd29853214860d2d060495a9ac80c4db1a87
|
File details
Details for the file imgshift-0.1.2-py3-none-any.whl.
File metadata
- Download URL: imgshift-0.1.2-py3-none-any.whl
- Upload date:
- Size: 45.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e49c3926cc9857298578b0afcbd7f64916077890cda4d06130e0a33e6c091f8
|
|
| MD5 |
f0117b3e0cba10ce3a568046c275a819
|
|
| BLAKE2b-256 |
aebf6be5dcc4dd4ee1a8ff8804a57ea0d388e8be6c71b2e06a4d2a7042aebe8c
|