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

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.5.0.tar.gz (46.3 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.5.0-py3-none-win_amd64.whl (6.7 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3manylinux: glibc 2.35+ x86-64

slimg-0.5.0-py3-none-manylinux_2_35_aarch64.whl (5.4 MB view details)

Uploaded Python 3manylinux: glibc 2.35+ ARM64

slimg-0.5.0-py3-none-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

slimg-0.5.0-py3-none-macosx_10_12_x86_64.whl (6.0 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: slimg-0.5.0.tar.gz
  • Upload date:
  • Size: 46.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for slimg-0.5.0.tar.gz
Algorithm Hash digest
SHA256 37df75f28d9790c6b6291fffc13c0e962334448834e3d318af93f22dc879572d
MD5 134268e0aeeb935caac7eaeb127948f9
BLAKE2b-256 1dbf0d2991d9f4f2eea7fde69c2f3ad65779b6073400a1db04036be5831e300b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slimg-0.5.0-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.2.0 CPython/3.14.3

File hashes

Hashes for slimg-0.5.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 415aa1faa63f345a73b3942b59e75c0f9200e8f44a64313d8f3e648fc58b37ab
MD5 2f1b15d2bab3acbbc70eead8f8266ce1
BLAKE2b-256 155104ba7759f95ae1c31be55975b51799dfd478dc57d25b8121a8779c9a24e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slimg-0.5.0-py3-none-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 23206f5163828dd771d1ba728ec968a5bf727fa2cf397419c9230456ac783e34
MD5 e3ba60fae2d07274891fb039c118d7cf
BLAKE2b-256 7e1e41af3a5a18909bc00c1c18a813bdc226c8424dc143d9cd4ef8e595cf7645

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slimg-0.5.0-py3-none-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 dbdcb160c39b46a9598e3974bf327e2f2a1f97c260274a3048c9ece6766df5c9
MD5 fbe1337093154ed337e1000dd74e0623
BLAKE2b-256 5aa7724800678002d98297f5dae6a594261889fcd83727b0c32e6979e10de90e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slimg-0.5.0-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.2.0 CPython/3.14.3

File hashes

Hashes for slimg-0.5.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 76e28dfe34db82d34f655824e2d150e5cadb5b186b2b89ab453b4c9c75a00ebf
MD5 8d3d76afacb662debaa2e541733993f5
BLAKE2b-256 0fecf69baa9d812a7bcc08a6ad1ce33d17293e882082bc3622936e1317225969

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slimg-0.5.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cb71480333d43d4cdb27dc59cd4ce73a8dc8963903f13e9db73e9447ac507396
MD5 52f5cfcbd4c1e101637413e481374e94
BLAKE2b-256 54c5438af96b01dd569b84a8906f3d99ada1cad1e3d67a10cd40d3177404fdd8

See more details on using hashes here.

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