wasm-tiff-merger
v0.1.1
Published
Merge multiple images into one TIFF in the browser with Rust + WebAssembly.
Readme
wasm-tiff-merger
wasm-tiff-merger is an npm package that wraps the Rust/WASM TIFF merger so Vue 3, React, and plain static HTML projects can all call the same API.
Package outputs
dist/index.js: ESM build for modern bundlers such as Vite.dist/index.cjs: CommonJS build.dist/browser.js: IIFE build that exposeswindow.WasmTiffMerger.dist/wasm_tiff_merger_bg.wasm: WASM asset loaded by the package.
Build
npm install
npm run buildThe build will:
- Compile Rust to
wasm32-unknown-unknown. - Generate
pkg/bindings withwasm-bindgen. - Bundle the npm package with Rollup.
API
import { init, mergeImagesToTiff } from "wasm-tiff-merger";
await init();
const tiff = await mergeImagesToTiff([file1, file2, file3]);
const smaller = await mergeImagesToTiff([file1, file2, file3], {
mode: "lossy",
lossyQuality: 65
});mergeImagesToTiff(images, options?) supports:
mode:"lossless"(default) or"lossy".lossyQuality:1-100, only used whenmode: "lossy"(default70).
Supported image inputs:
Uint8ArrayArrayBufferArrayBufferViewBlob/File
Vue 3
<script setup lang="ts">
import { mergeImagesToTiff } from "wasm-tiff-merger";
async function onChange(event: Event) {
const files = Array.from((event.target as HTMLInputElement).files ?? []);
const tiff = await mergeImagesToTiff(files);
const url = URL.createObjectURL(new Blob([tiff], { type: "image/tiff" }));
const link = document.createElement("a");
link.href = url;
link.download = "merged.tiff";
link.click();
URL.revokeObjectURL(url);
}
</script>Full example: examples/vue3/App.vue
React
import { mergeImagesToTiff } from "wasm-tiff-merger";
async function onChange(event: React.ChangeEvent<HTMLInputElement>) {
const files = Array.from(event.target.files ?? []);
const tiff = await mergeImagesToTiff(files);
const url = URL.createObjectURL(new Blob([tiff], { type: "image/tiff" }));
const link = document.createElement("a");
link.href = url;
link.download = "merged.tiff";
link.click();
URL.revokeObjectURL(url);
}Full example: examples/react/App.tsx
Static HTML
<script src="./browser.js"></script>
<script>
async function createTiff(files) {
await window.WasmTiffMerger.init({
wasmSource: "./wasm_tiff_merger_bg.wasm"
});
return window.WasmTiffMerger.mergeImagesToTiff(files);
}
</script>Full example: examples/static/index.html
Publish notes
- Keep
pkg/anddist/in the published package. - For bundlers, the default
init()path resolution uses the copiedwasm_tiff_merger_bg.wasmnext to the JS bundle. - For direct
<script>usage, passwasmSourceexplicitly if the browser bundle is not served from the same folder as the.wasmfile.
