Skip to main content

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 OR Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slimg-0.3.1.tar.gz (40.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

slimg-0.3.1-py3-none-win_amd64.whl (3.9 MB view details)

Uploaded Python 3Windows x86-64

slimg-0.3.1-py3-none-manylinux_2_34_x86_64.whl (4.8 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

slimg-0.3.1-py3-none-manylinux_2_34_aarch64.whl (3.9 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ ARM64

slimg-0.3.1-py3-none-macosx_11_0_arm64.whl (3.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

slimg-0.3.1-py3-none-macosx_10_12_x86_64.whl (4.4 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file slimg-0.3.1.tar.gz.

File metadata

  • Download URL: slimg-0.3.1.tar.gz
  • Upload date:
  • Size: 40.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slimg-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b2a5e0ecc4e03a88c5e04c268e8e41a86b462176f457c14cc49858b5124b8ef0
MD5 12083c7cb629852ae1d2f4c8719b8aae
BLAKE2b-256 77744fc680a273f38e7ad9b38ef0e48fecbb09395edd05299ab6e1df662e83ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimg-0.3.1.tar.gz:

Publisher: publish.yml on clroot/slimg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slimg-0.3.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: slimg-0.3.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 3.9 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slimg-0.3.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f552dfa6ac8fc15183fbb918e8257101e701d8f5710c1c3333a13783de78ff15
MD5 75f8a737a7d1fd49159bca39c9ed50b5
BLAKE2b-256 1eb0f66d4eeb9271d56ab93567c8194b63eeb4df135352f096732c519a9f288d

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimg-0.3.1-py3-none-win_amd64.whl:

Publisher: publish.yml on clroot/slimg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slimg-0.3.1-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for slimg-0.3.1-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 270e838a5a581ef72c14d22b3f5a984c360bc26e94a7d3f8a24e5e0b4cff8cbe
MD5 09040da0661ecc202350c19cc18a5710
BLAKE2b-256 9694d12f0dd83631b7b5056d2c15c31d73604608d7a38fa5166f51d6572e9226

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimg-0.3.1-py3-none-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on clroot/slimg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slimg-0.3.1-py3-none-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for slimg-0.3.1-py3-none-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f900c2986c3e9856357cecb8e2ace66eef31a4b859fc2e4d5e7101ac5bbddce1
MD5 8ccfb2a3d32edb2a7686e437d18d4da2
BLAKE2b-256 9069bde5ac83afe80e827280c4b72d64304cf084d518c94ab7858096125d8b87

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimg-0.3.1-py3-none-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on clroot/slimg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slimg-0.3.1-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: slimg-0.3.1-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slimg-0.3.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 694685453f16019c95617233dd4af5190700781d30fe8fa1efacf219f14f612c
MD5 d74a07853f32a3c97bf99846768d8381
BLAKE2b-256 e3bb336933ed9344aaad2b4d9fb679ff171ab53495a645fb0c371c92173c6968

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimg-0.3.1-py3-none-macosx_11_0_arm64.whl:

Publisher: publish.yml on clroot/slimg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slimg-0.3.1-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for slimg-0.3.1-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e0b09bb4f30b4c00eb3daab5201c621746054dc4d61701bbaaae1be83d44ed7a
MD5 ea9a2565d66bedc4f75a23129606ea18
BLAKE2b-256 0dce7d9fa0c878193c8eeb47ce0793e7f36a7587871a2218b0868bd20265b3c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimg-0.3.1-py3-none-macosx_10_12_x86_64.whl:

Publisher: publish.yml on clroot/slimg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page