Skip to content

Python API

arrow edited this page Aug 4, 2026 · 2 revisions

Python API

Encode and save

from PIL import Image
import wimf

image = Image.open("source.png")
wimf.save("output.wimf", image, quality=7, preset="Balanced", codec="auto")

Lossless output:

wimf.save("exact.wimf", image, lossless=True)

The presets are Fast, Balanced, and Extreme. Forced codecs are raw, predictive, palette, and wavelet; auto selects per tile.

Decode

decoded = wimf.open("output.wimf")
decoded.pil.save("decoded.png")

Pillow integration

Import WIMF once to register the Pillow plugin:

import wimf
from PIL import Image

image = Image.open("photo.wimf")
image.save("copy.wimf", format="WIMF", lossless=True)

The canonical registered extension is .wimf; .wim2 is not a filename extension.

ROI decoding

region = wimf.decode("large.wimf", roi=(256, 128, 512, 512))
region.pil.save("region.png")

Inspect without a full decode

details = wimf.inspect("output.wimf")
print(details["tile_modes"])
print(details["metadata"])

Metadata

wimf.save("tagged.wimf", image, metadata={"author": "Example", "purpose": "test"})

Metadata is compressed, not encrypted.

Protection and history

encoder = wimf.WIMFEncoder(image).set_anti_rot(True)
encoder.add_chrono_state(next_image)
payload = encoder.encode(lossless=True)

Use decode_chrono_state(index) for random state access.

Clone this wiki locally