1.0.1 • Published 2 months ago

@kynsonszetau/png2webp v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

png2webp

This is a simple WASM library designed to convert PNG images to WebP format.

Usage

Brower & Node.js:

import init from '@kynsonszetau/png2webp';
import { png2webp } from '@kynsonszetau/png2webp';

await init();

// data is an Uint8Array containing PNG data
png2webp(data);

Cloudflare Workers:

import { png2webp, initSync } from '@kynsonszetau/png2webp';
// Cloudflare workers does not support compiling WASM bytecode during runtime
// We have to initialize it in a different way
import png2webpWasm from '@kynsonszetau/png2webp/png2webp_bg.wasm';

initSync(png2webpWasm);

png2webp(data);

Function signatures of the above functions are included in png2webp.min.d.mts

How it works

The main functionality of this project is provided by the png2webp function in the src/lib.rs file. This function takes a PNG image data as input and returns the converted WebP image data.

The function uses image crate for handling the image conversion. The wasm-bindgen crate is used to provide a bridge between Rust and JavaScript, allowing the png2webp function to be called from JavaScript code as WASM.

Building the Project

To build the project, you can use the wasm-pack command-line tool:

wasm-pack build --target web

Or use the build script included in the repository:

npm run build
1.0.1

2 months ago

1.0.0

2 months ago