Fast image optimization library powered by Rust
Project description
slimg
Python bindings for the slimg image optimization library.
Supports macOS (Apple Silicon, Intel), Linux (x86_64, ARM64), and Windows (x86_64) -- native extensions are bundled in pre-built wheels.
Installation
pip install slimg
Usage
import slimg
# Open an image file
image = slimg.open("photo.jpg")
print(f"{image.width}x{image.height} {image.format}")
# Convert to WebP
result = slimg.convert(image, format="webp", quality=80)
result.save("photo.webp")
# Optimize in the same format
result = slimg.optimize_file("photo.jpg", quality=75)
result.save("optimized.jpg")
# Resize by width (preserves aspect ratio)
resized = slimg.resize(image, width=800)
result = slimg.convert(resized, format="png")
result.save("thumbnail.png")
# Crop to aspect ratio (centre-anchored)
cropped = slimg.crop(image, aspect_ratio=(16, 9))
# Crop by pixel region
cropped = slimg.crop(image, region=(100, 50, 800, 600))
# Extend (pad) to aspect ratio with a fill colour
extended = slimg.extend(image, aspect_ratio=(1, 1), fill=(255, 255, 255))
# Extend with transparent padding (default)
extended = slimg.extend(image, aspect_ratio=(1, 1))
Supported Formats
| Format | Decode | Encode | Notes |
|---|---|---|---|
| JPEG | Yes | Yes | MozJPEG encoder |
| PNG | Yes | Yes | OxiPNG + Zopfli compression |
| WebP | Yes | Yes | Lossy encoding via libwebp |
| AVIF | Yes | Yes | ravif encoder; dav1d decoder |
| QOI | Yes | Yes | Lossless, fast encode/decode |
| JPEG XL | Yes | No | Decode-only |
API Reference
Functions
| Function | Description |
|---|---|
open(path) |
Decode an image file from disk |
decode(data) |
Decode image bytes (auto-detects format) |
convert(image, format, quality=80) |
Encode image in a target format |
resize(image, *, width/height/exact/fit/scale) |
Resize an image |
crop(image, *, region/aspect_ratio) |
Crop an image |
extend(image, *, aspect_ratio/size, fill) |
Pad an image canvas |
optimize(data, quality=80) |
Re-encode bytes to reduce file size |
optimize_file(path, quality=80) |
Read a file and re-encode |
Types
| Type | Description |
|---|---|
Format |
JPEG, PNG, WEBP, AVIF, JXL, QOI |
Image |
Decoded image with width, height, data, format |
Result |
Encoded output with data, format, and save(path) |
Resize |
Factory: width, height, exact, fit, scale |
Crop |
Factory: region, aspect_ratio |
Extend |
Factory: aspect_ratio, size |
SlimgError |
Error with subclasses: UnsupportedFormat, UnknownFormat, EncodingNotSupported, Decode, Encode, Resize, Crop, Extend, Io, Image |
Supported Platforms
| Platform | Architecture | Status |
|---|---|---|
| macOS | Apple Silicon (aarch64) | Supported |
| macOS | Intel (x86_64) | Supported |
| Linux | x86_64 | Supported |
| Linux | ARM64 (aarch64) | Supported |
| Windows | x86_64 | Supported |
Requirements
- Python 3.9+
License
MIT
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 Distributions
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 slimg-0.5.1.tar.gz.
File metadata
- Download URL: slimg-0.5.1.tar.gz
- Upload date:
- Size: 46.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
587fcc4990c1895e8baa40b74034fe58ee65294e345f60afeb1eb4dc7f8a1fa8
|
|
| MD5 |
9da580105ed28d977cbe574ccaa55399
|
|
| BLAKE2b-256 |
974710ae82b6c89c6ce55fecc4b89fe5178f1115287c8e421fb99a47122c7002
|
File details
Details for the file slimg-0.5.1-py3-none-win_amd64.whl.
File metadata
- Download URL: slimg-0.5.1-py3-none-win_amd64.whl
- Upload date:
- Size: 6.7 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3bea209febd20b8daefd3af29629bc8e5159ac122213b19739a10714ab792da
|
|
| MD5 |
a4460ffe6c7e781854600e51201f5e51
|
|
| BLAKE2b-256 |
0126712703e5fe4d8cfba518ecf71f1c16e5d6ef2e07ab175d79efe04a54eae8
|
File details
Details for the file slimg-0.5.1-py3-none-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: slimg-0.5.1-py3-none-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 6.7 MB
- Tags: Python 3, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4d947d5c348979a517eb084ac0318bf35c2b0a13de4e492e649dc0e31a10c47
|
|
| MD5 |
a1df2b8317a12c6959682e547dd736d6
|
|
| BLAKE2b-256 |
4f4e83bb8099026c247bd6bbc25f8b6c1c2fb58de70d6c50dcab92da828d65a3
|
File details
Details for the file slimg-0.5.1-py3-none-manylinux_2_35_aarch64.whl.
File metadata
- Download URL: slimg-0.5.1-py3-none-manylinux_2_35_aarch64.whl
- Upload date:
- Size: 5.4 MB
- Tags: Python 3, manylinux: glibc 2.35+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d8671e4896eddbc7ce5371a0a1c5791a58af6ba7d4f1605c5d0e8a3c1aeb6eb
|
|
| MD5 |
3150d1074a2ef51828f6f7f5bd9d24e2
|
|
| BLAKE2b-256 |
396cb01e29414650765f8d1036728a18403bf226440167c6f56069d29815f6e1
|
File details
Details for the file slimg-0.5.1-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: slimg-0.5.1-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.6 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab1377d0230c05e626a251d6821e941b4172a200476b19e2ac014f60e19fd7e7
|
|
| MD5 |
c2460dd9ae4cf656b8bce74b58325ca8
|
|
| BLAKE2b-256 |
f9d395cb1a481583be174fb9dab284ae3fb06731f84271677ede752a31c3b58f
|
File details
Details for the file slimg-0.5.1-py3-none-macosx_10_12_x86_64.whl.
File metadata
- Download URL: slimg-0.5.1-py3-none-macosx_10_12_x86_64.whl
- Upload date:
- Size: 6.0 MB
- Tags: Python 3, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d87cc9d908154a4fa10a5bfc23c457d5f76dbb8719ead2697432d5fecb38c7b
|
|
| MD5 |
342fd9624e7bc295cb56d1e563069272
|
|
| BLAKE2b-256 |
69bc5c427dc32341f7291ea629bf09d01f6a49165adba4cb73395fcbb243be1d
|