import { Transformer } from '@napi-rs/image'
export async function transform() {
const imageResponse = await fetch(
'https://upload.wikimedia.org/wikipedia/commons/5/5d/ISS-45_EVA-2_%28a%29_Scott_Kelly.jpg'
)
const imageBytes = await imageResponse.arrayBuffer()
const transformer = new Transformer(imageBytes)
const webp = await transformer.toWebp()
}use napi::bindgen_prelude::*;
use napi_derive::napi;
#[napi]
pub struct Transformer {
inner: Uint8Array,
}
#[napi]
impl Transformer {
#[napi(constructor)]
pub fn new(inner: Uint8Array) -> Self {
Self { inner }
}
#[napi]
pub fn to_webp(&self) -> Result<Uint8Array> {
let image = image::load_from_memory(&self.inner)?;
let webp = image.to_webp().map_err(|e| Error::from(e.to_string()))?;
Ok(webp.into())
}
}Current napi-rs source CI:
Use Node.js 22.13+ or 24+ for the current build CLI. Bun is best-effort in upstream CI; Deno is not in the blocking native-addon matrix.
Read the complete support contract →| ia32 | x64 | arm64 | arm | WASI | |
|---|---|---|---|---|---|
| Windows MSVC | |||||
| macOS | |||||
| Linux glibc | |||||
| Linux musl | |||||
| FreeBSD | |||||
| Android | |||||
| WebAssembly |
Included in the maintained scaffold's build/package matrix.
Not included in the maintained scaffold; it may require manual support or may be unavailable.
Accepted targets and test coverage →