Skip to main content

Blanket

Image processing in Python. Pixel work in Rust.

CI Python 3.12+ License: MIT

Blanket is a Rust-backed image library with a familiar, Pillow-shaped Python API. Open, transform, and save images using native pixel kernels, with no Pillow or other Python packages required at runtime.

from blanket import Image, ImageOps

with Image.open("photo.jpg") as image:
    upright = ImageOps.exif_transpose(image)
    thumbnail = ImageOps.fit(upright, (256, 256), method=Image.Resampling.LANCZOS)
    thumbnail.save("thumbnail.webp", quality=85)

Installation · Examples · Formats · API notes · Contributing

Why Blanket?

  • Familiar image APIs. Work with Image, ImageOps, ImageChops, ImageEnhance, ImageFilter, ImagePalette, and ImageStat.
  • Native processing. Rust kernels use SIMD and parallel execution for supported operations, with small-image fast paths.
  • Modern formats. Read and write JPEG XL, WebP, AVIF, and HEIC/HEIF alongside PNG, JPEG, TIFF, BMP, GIF, and ICO. Export single-page PDFs.
  • Explicit precision. Keep 10-, 12-, and 16-bit samples in supported workflows, and choose when to convert to 8 bits.
  • Python interoperability. Import array data, work with binary streams, and convert explicitly to Pillow when you need it.

Blanket is currently alpha software. It implements a focused subset of Pillow's API, centered on 1, L, LA, RGB, RGBA, HSV, CMYK, YCbCr, and LAB images, with integer I and I;16 modes, floating-point F, and limited indexed P and PA support. It is not a drop-in replacement for PIL (yet).

See ImageChops for arithmetic and blend modes, and ImageStat for per-band statistics.

Installation

Blanket requires Python 3.12+. Install from this repository after setting up the native build prerequisites below:

pip install pyblanket

See the development notes for information on building from source.

Examples

Convert between formats

from blanket import Image

with Image.open("input.png") as image:
    image.convert("RGB").save("output.jpg", quality=85)
    image.save("output.jxl", lossless=True)

File extensions select the output format. For binary streams, pass it explicitly:

from io import BytesIO
from blanket import Image

with Image.open("input.png") as image:
    buffer = BytesIO()
    image.save(buffer, format="PNG")
    png_bytes = buffer.getvalue()

Optimize a save without additional loss

from blanket import Image
from blanket.Compressor import LosslessImageCompressor

compressor = LosslessImageCompressor(effort=7)
with Image.open("input.png") as image:
    image.save("optimized.png", compressor=compressor)
    image.convert("RGB").save("optimized.jpg", quality=90, compressor=compressor)
    image.save("optimized.jxl", lossless=True, compressor=compressor)
    image.save("optimized.heic", lossless=True, compressor=compressor)

The compressor keeps the smallest encoding that preserves the normal save's decoded pixels. It supports PNG, JPEG, JPEG XL, and HEIF/HEIC; higher effort tries more settings and takes longer. JPEG optimization preserves DCT coefficients. This optimizes the requested save, not the original source file: lossy save settings still introduce their normal loss. See the Compressor module for the API, format-specific behavior, and compression benchmarks.

For smaller output with bounded additional pixel error, pass LossyImageCompressor(max_rmse=2.0, effort=7) from blanket.Compressor. It searches PNG color precision or lower JPEG, WebP, JPEG XL, AVIF, and HEIF/HEIC quality settings, preserving alpha and checking decoded RGB error against the normal save. The result never exceeds the normal save's size.

Resize, enhance, and filter

from blanket import Image, ImageEnhance, ImageFilter, ImageOps

with Image.open("photo.jpg") as image:
    resized = ImageOps.contain(image, (1200, 800))
    enhanced = ImageEnhance.Contrast(resized).enhance(1.2)
    sharpened = enhanced.filter(ImageFilter.UnsharpMask(radius=2, percent=150))
    sharpened.save("edited.png")

resize() supports all six Image.Resampling filters. ImageOps includes cropping, padding, flips, color adjustments, and EXIF orientation correction. ImageFilter provides blurs, convolution kernels, rank filters, and 3D color LUTs.

Build an image with transparency

from blanket import Image

background = Image.new("RGBA", (640, 480), "white")
overlay = Image.new("RGBA", (160, 160), (30, 100, 220, 128))
background.alpha_composite(overlay, dest=(40, 40))
background.save("composite.png")

Use paste() for masked placement, putalpha() to set transparency, and split() / Image.merge() to work with individual channels.

Work with NumPy and high-bit-depth images

NumPy is optional. fromarray() accepts array-interface objects, including strided arrays:

import numpy as np
from blanket import Image

samples = np.full((64, 64, 3), 713, dtype=np.uint16)
image = Image.fromarray(samples, bit_depth=10)
image.save("exact.png")
image.convert("RGB", bit_depth=8).save("preview.jpg")

image.bit_depth reports sample precision. Copying, conversion, pixel access, splitting, cropping, transposition, and resizing preserve high-bit-depth samples. Other processing operations require conversion to 8 bits. See high-bit-depth images for storage and format-specific behavior.

Supported formats

Format Read Write Notes
PNG Yes Yes Lossless; high-bit-depth and indexed output
JPEG Yes Yes 8-bit output; convert RGBA to RGB before saving
JPEG XL Yes Yes Lossy or lossless; high-bit-depth support
TIFF Yes Yes First image only; uncompressed output
WebP Yes Yes Lossy or lossless; first frame only
AVIF Yes Yes Primary image only; 8-bit, lossy output
HEIC / HEIF Yes Yes HEVC; retains 8-, 10-, or 12-bit source depth
PDF — Yes Single page; lossless 8-bit output with transparency
BMP Yes Yes 8-bit output; uncompressed
GIF Yes Yes First frame only; single-frame output, 256 colors and binary transparency
ICO Yes Yes Largest icon on read; one PNG icon on write, 1–256 pixels per dimension

Encoder settings and their defaults are listed in the format guide. HEIF lossless compression can still change RGB values during RGB/YUV conversion.

Compatibility and scope

  • Image modes: 8-bit processing supports 1, L, LA, RGB, RGBA, HSV, CMYK, YCbCr, and LAB. Integer I, I;16, I;16L, and I;16B and floating-point F support pixel access, conversion, copying, cropping, transposition, and resizing. F also supports transforms and TIFF interchange. Indexed P and PA images have a smaller supported operation set.
  • Print and luma/chroma modes: CMYK uses raw channels without ICC transforms; JPEG and 8-bit TIFF retain CMYK on read, and JPEG, TIFF, and PDF support CMYK output. CMYK save-time compression optimization is unsupported. YCbCr saves to JPEG through RGB and opens back as RGB. Convert either mode to RGB for other output formats or direct quantization.
  • LAB: 8-bit CIE Lab* supports pixel operations and TIFF interchange. Native, statically linked LittleCMS converts between sRGB and D50 LAB; other conversions pass through RGB. LAB save-time compression optimization is unsupported.
  • Metadata: PNG, JPEG, and uncompressed JPEG XL metadata boxes supply EXIF/XMP for orientation handling. Saving writes pixels only; metadata is not preserved.
  • Multiple frames: animation and multipage editing are not supported.
  • High bit depth: sample retention is supported for selected operations and formats; HDR tone mapping and HEIF HDR/ICC metadata retention are not.
  • Pillow interop: image.to_pillow() creates a Pillow image when Pillow is installed. High-bit-depth images must first be converted to 8 bits.

See the usage and API notes for operation-specific restrictions, palette support, and interoperability examples.

Performance

The benchmark suite compares Blanket and Pillow using equal in-memory inputs and eager decoding. After completing the development setup below, run it with a release build:

maturin develop -r --extras test --uv
uv run --no-sync scripts/benchmark.py --sizes web

Use --all for the full suite or --sections Resize ImageOps to select operations. Results depend on image size, operation, codec settings, and hardware. The benchmark guide explains baseline comparisons and reproducible runs.

Contributing

With the build prerequisites installed, set up a development environment and run the checks:

uv sync --no-install-project --extra test
uv tool install maturin
maturin develop --extras test --uv
cargo fmt --check
cargo clippy -- -D warnings
cargo test
uv run --no-sync pytest -q
uv run --no-sync scripts/verify_behavior.py

The native core lives in crates/, the Python API in python/blanket/, and compatibility tests in tests/. Include a focused regression test with bug fixes and new features. open an issue to report a problem.

License

Blanket is licensed under the MIT License. See third-party licenses for native dependency notices.

Metadata

Release files for pyblanket 0.0.2

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

Source distribution (sdist)

Source distribution for pyblanket 0.0.2
File Size Uploaded Provenance
pyblanket-0.0.2.tar.gz 178.6 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for pyblanket 0.0.2
File Interpreter ABI Platform
pyblanket-0.0.2-cp312-abi3-manylinux_2_39_x86_64.whl CPython 3.12 abi3 Linux glibc 2.39+ x86-64 Details
pyblanket-0.0.2-cp312-abi3-manylinux_2_39_aarch64.whl CPython 3.12 abi3 Linux glibc 2.39+ ARM64 Details
pyblanket-0.0.2-cp312-abi3-macosx_26_0_arm64.whl CPython 3.12 abi3 macOS 26.0+ ARM64 Details

Total release size: 44.4 MB

Release files / pyblanket-0.0.2.tar.gz

Download URL pyblanket-0.0.2.tar.gz
Size 178.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fb6812ebfb2c83a6e4bca31c730c373d97d9bed7ddd2a3209f7381874d586d98
BLAKE2b-256 checksum
How to use checksums
e73212e21387a0f14210f222a2fc719a78c2596a3433e3220f43cbe9cf6b0fb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release files / pyblanket-0.0.2-cp312-abi3-manylinux_2_39_x86_64.whl

Download URL pyblanket-0.0.2-cp312-abi3-manylinux_2_39_x86_64.whl
Size 15.4 MB
Tags CPython 3.12 Linux glibc 2.39+ x86-64 abi3
SHA-256 checksum
How to use checksums
015c432b7c586fd9bf78511f7336b9d3a74f3930698525b047f41beb66555081
BLAKE2b-256 checksum
How to use checksums
96f7247cfa18882a57440f1c311a2c70b651305b6f9090d73698d5af7fc1898e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release files / pyblanket-0.0.2-cp312-abi3-manylinux_2_39_aarch64.whl

Download URL pyblanket-0.0.2-cp312-abi3-manylinux_2_39_aarch64.whl
Size 15.8 MB
Tags CPython 3.12 Linux glibc 2.39+ ARM64 abi3
SHA-256 checksum
How to use checksums
ce6098cda8bd8bc54a5cf57cda29a6a73e3d561d2c440952657ab7ad636df564
BLAKE2b-256 checksum
How to use checksums
50026725240bdaa71c479291f5568432754761b2ce7550fc2857e0d5fdc602f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release files / pyblanket-0.0.2-cp312-abi3-macosx_26_0_arm64.whl

Download URL pyblanket-0.0.2-cp312-abi3-macosx_26_0_arm64.whl
Size 13.0 MB
Tags CPython 3.12 abi3 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
4433cb9506f2b3b99d9c85f15828742e63a2bc569e5f128c78afe1ac503b51bf
BLAKE2b-256 checksum
How to use checksums
4498a873cf879b850a8c652eb4b25a4817e533a74c9d174fd96ab2dd995d98fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Security for pyblanket 0.0.2

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.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for pyblanket-0.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

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.

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