Skip to main content

slimg

PyPI

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 Yes libjxl encoder/decoder

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

Metadata

Release files for slimg 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slimg 0.6.1
File Size Uploaded Provenance Actions
slimg-0.6.1.tar.gz 50.6 kB Without provenance Details for slimg-0.6.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for slimg 0.6.1
File Actions
slimg-0.6.1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for slimg-0.6.1-py3-none-win_amd64.whl
slimg-0.6.1-py3-none-manylinux_2_35_x86_64.whl Python 3 none Linux glibc 2.35+ x86-64 Details for slimg-0.6.1-py3-none-manylinux_2_35_x86_64.whl
slimg-0.6.1-py3-none-manylinux_2_35_aarch64.whl Python 3 none Linux glibc 2.35+ ARM64 Details for slimg-0.6.1-py3-none-manylinux_2_35_aarch64.whl
slimg-0.6.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for slimg-0.6.1-py3-none-macosx_11_0_arm64.whl
slimg-0.6.1-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for slimg-0.6.1-py3-none-macosx_10_12_x86_64.whl

Total release size: 29.4 MB

Release files / slimg-0.6.1.tar.gz

Download URL slimg-0.6.1.tar.gz
Size 50.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ac1eaf35f5add2387a210a58bedd0fb8d4663d5e8089e3304bd133e6c7d3b22a
BLAKE2b-256 checksum
How to use checksums
3aebb71aea6257051b7a4229776501042daed64359e28cdebc5c3a57659b8571
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / slimg-0.6.1-py3-none-win_amd64.whl

Download URL slimg-0.6.1-py3-none-win_amd64.whl
Size 6.8 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
ff59a94d3435d9868d5a4b9397c06500f218ba9f6f23acc6c932753c817564bf
BLAKE2b-256 checksum
How to use checksums
7232a062e7252e9cae08f8d22beab7d193c651a3dfb0acb5b2645514468a0bde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / slimg-0.6.1-py3-none-manylinux_2_35_x86_64.whl

Download URL slimg-0.6.1-py3-none-manylinux_2_35_x86_64.whl
Size 6.7 MB
Tags Linux glibc 2.35+ x86-64 Python 3
SHA-256 checksum
How to use checksums
248856e15648ee4ef85a6e3f7d3c4856f387eec35d32a7355da5bcbad026b55e
BLAKE2b-256 checksum
How to use checksums
5ab800e5203ee8e2659320c787e5654ac516492c89592fa064b1444e6cc73147
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / slimg-0.6.1-py3-none-manylinux_2_35_aarch64.whl

Download URL slimg-0.6.1-py3-none-manylinux_2_35_aarch64.whl
Size 5.5 MB
Tags Linux glibc 2.35+ ARM64 Python 3
SHA-256 checksum
How to use checksums
f8ca24097b72ce291be8142fe16759af2478c1916e49030785532c06e6860216
BLAKE2b-256 checksum
How to use checksums
654eae638d59f8e6495ddab3ce03b81ab8d3e1601aeb74501b7e15377557f38f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / slimg-0.6.1-py3-none-macosx_11_0_arm64.whl

Download URL slimg-0.6.1-py3-none-macosx_11_0_arm64.whl
Size 4.5 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
be7a87e647ce90cc740d9171d915a556270bbb21d1e7b1069458d4a79792ae98
BLAKE2b-256 checksum
How to use checksums
d07400c68367d2ad88b83be11b8f8a9da019639e09ced2d383a03447057b0cdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / slimg-0.6.1-py3-none-macosx_10_12_x86_64.whl

Download URL slimg-0.6.1-py3-none-macosx_10_12_x86_64.whl
Size 5.9 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
74b4da058d1f1b089becbd8c24da9cdf372e39fce031f5c74a143501aaa38cf2
BLAKE2b-256 checksum
How to use checksums
8bd51f6448558b2f06af4cdb9089d2e9db944f76b7119ffd17c7e1a3818c38e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for slimg 0.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page