Pillow plugin for JPEG-XL, using Rust for bindings.
Maintained. Last release 4 months ago, commits in 2 of the last 26 weeks. Weaker on commit activity and contributor spread.
$
pip install pillow-jxl-pluginpillow-jpegxl-plugin
Pillow plugin for JPEG-XL, using Rust for bindings.
Features
- JPEG-XL Plugin for Pillow
- Encoder/Decoder to work with JPEG-XL using safe wrapper
- Support EXIF metadata encoding
Install via PIP
pip install pillow-jxl-plugin
Build from source
Make sure Rust installed, then run:
git clone https://github.com/Isotr0py/pillow-jpegxl-plugin
cd pillow-jpegxl-plugin
pip install -e .[dev] -v
If you have libjxl installed and want to use dynamic link, run:
pip install -e .[dev] -v --config-settings=build-args="--features=dynamic"
Development
- Python code is formatted and linted with
ruff, while Rust code is checked withcargo fmtandcargo clippyvia pre-commit. - Install the tooling once with
pip install -e .[dev]and thenpre-commit install. - Run the suite manually with
pre-commit run --all-filesbefore opening a pull request.
Plugin Usage
Use import pillow_jxl to register the plugin in your code.
Example:
from io import BytesIO
import pillow_jxl
from PIL import Image
# Lossless encode a png image
with Image.open("example.png") as img:
img.save("example.jxl",lossless=True)
# Encode image with JPEG-Style quality
with Image.open("example.png") as img:
img.save("example.jxl", quality=98)
# Lossless construct from a jpeg image
with Image.open("example.jpg") as img:
img.save("example.jxl",lossless=True)
# Decode jxl image
with Image.open("example.jxl") as img:
display(img)
# Encode/decode jxl image to buffer
buffer = BytesIO()
with Image.open("example.png") as img:
img.save(buffer, format="JXL")
jxl_bytes = buffer.getvalue()
img = Image.open(BytesIO(jxl_bytes))
display(img)