This is a proof of concept Typst WASM-plugin to allow simple image editing functions from within Typst, written in Rust. It uses the wasm-minimal-protocol crate to define the plugin functions. The image editing functionality is provided by the image crate.
The simplest way to use this plugin is to import the package grayness from Typst Universe into your typst code and use it's wrapper functions:
#import "@preview/grayness:0.6.0":*
#let imagedata = read("path-to-your-picture.jpg", encoding: none)
#image-grayscale(imagedata)The manual provides further details.
You can also use this plugin directly, e.g. if you have compiled the WASM binary yourself.
#let plg = plugin("grayness.wasm")
#let imagedata = read("path-to-your-picture.jpg", encoding: none)
#image(plg.grayscale(imagedata))To compile this plugin, you need to have a working Rust toolchain. Then you need to install the wasm32-unknown-unknown target:
rustup target add wasm32-unknown-unknownThen, build the crate with this target:
cargo build --release --target wasm32-unknown-unknown