Getting started
Install Blanket from PyPI:
With pip:
pip install pyblanket
With uv:
uv add pyblanket
Open, edit, and save
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)
Paths select a save format by extension. For a binary stream, pass format:
from io import BytesIO
from blanket import Image
with Image.open("input.png") as image:
output = BytesIO()
image.save(output, format="PNG")
encoded = output.getvalue()
Choose a mode
Use L for grayscale, RGB for color, and RGBA for color with alpha.
Most editing works on 8-bit images in these modes. quantize() creates an
indexed P image for palette output; convert it before general editing.
For 10-, 12-, or 16-bit inputs, see high bit depth.
JPEG does not support RGBA output. Convert before saving:
image.convert("RGB").save("photo.jpg", quality=85)
Find the next API
The Image reference covers pixels, transforms, composition, and quantization. Use ImageOps for common adjustments, ImageFilter for filtering, and ImageEnhance for enhancement. Check formats and save options before choosing an encoder.