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

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.6.0.tar.gz (50.6 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.6.0-py3-none-win_amd64.whl (6.8 MB view details)

Uploaded Python 3Windows x86-64

slimg-0.6.0-py3-none-manylinux_2_35_x86_64.whl (6.7 MB view details)

Uploaded Python 3manylinux: glibc 2.35+ x86-64

slimg-0.6.0-py3-none-manylinux_2_35_aarch64.whl (5.5 MB view details)

Uploaded Python 3manylinux: glibc 2.35+ ARM64

slimg-0.6.0-py3-none-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

slimg-0.6.0-py3-none-macosx_10_12_x86_64.whl (5.9 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: slimg-0.6.0.tar.gz
  • Upload date:
  • Size: 50.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for slimg-0.6.0.tar.gz
Algorithm Hash digest
SHA256 8d1570adefc17f6ddb381c6110ede98cc978c038347276c1eb10f1bcf80e8b63
MD5 bf609b9470c75df8a6a65f69133eea45
BLAKE2b-256 33628e8b92d2167359e97c8f8b0dfe90883ec8a0ade9a83abc03e985b9bfeda8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slimg-0.6.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 ea02470d698516cae2f27a374ed6cff22f19d516c3ac0563019ce1e3519b27a6
MD5 00e1581e5aa4c4ecd2371956d83f69c5
BLAKE2b-256 3a523b6de1b3be18a53ef88cc59615ca319221081636d9f79584396a57cf1949

See more details on using hashes here.

File details

Details for the file slimg-0.6.0-py3-none-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for slimg-0.6.0-py3-none-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 486713b098a07363fc0f6340e3c1ba42b4d9dacf87a290d33a2557840ff3e21c
MD5 03e2ce05fee44f2c81969685f308cb6b
BLAKE2b-256 6f3b4f503b67161aab86182d75178a753e47f4a4c90de578c1c152f29d9a4027

See more details on using hashes here.

File details

Details for the file slimg-0.6.0-py3-none-manylinux_2_35_aarch64.whl.

File metadata

File hashes

Hashes for slimg-0.6.0-py3-none-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 29546829b367a927cf50e93a059876610a3032f1b9cffe810cc55eecb2509479
MD5 932f5c1bfa051ab62de03d467381c146
BLAKE2b-256 ef0e4a67dbd578574c094083055c23ac6172e539f72b2756199fb13b3ec698cb

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slimg-0.6.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4bf28b157e6e1571cef018f2cc468117ebfda303c352a7dcb8fbb8a86277b865
MD5 0803e72d6f94f0750f235496644758b0
BLAKE2b-256 7632e54ec82ffe6cb9d8c7cbf7f607ac9afd893101a6d5d891426c4fe8d49f00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slimg-0.6.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7e46bfe152ca7cff2572c84c3c2ec9be7aa322d248525c604f35dba97d64c79b
MD5 260fc804e77d502c9af5771904a98f51
BLAKE2b-256 a3fa5e686cf0bebf422ba5ab23f60730718a2172f0b3988efe20047b454a84e9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.0 This release

6 files

0.5.1

6 files

0.5.0

6 files

0.3.1

6 files

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