WebAssembly Image manipulation with ClojureScript

144 views Asked by At

Request detail:

We want to do some image manipulation and conversion, in the browser. We prefer WebAssembly, because of its runtime efficiency. We want to use ImageMagick, because it can read SVG, Ai, and other formats that we want to work with. Our project is written in ClojureScript, compiled with Shadow-cljs.

Some libraries that we tried (this > https://github.com/dlemstra/magick-wasm) this is the error I get:

Closure compilation failed with 1 errors
--- node_modules/@imagemagick/magick-wasm/dist/index.umd.js:21
Transpilation of 'This or super in instance member' is not yet implemented.

or can't read SVG (this > https://github.com/KnicKnic/WASM-ImageMagick, even though it was a wrapper on ImageMagick)

or doesn't compile (this > https://silvia-odwyer.github.io/photon/ google-closure, which is part of Shadow-cljs ecosystem, returns error) this is the error I get:

Failed to inspect file
  /path-to-project/node_modules/@silvia-odwyer/photon/photon_rs_bg.wasm

it was required from
  /path-to-project/node_modules/@silvia-odwyer/photon/photon_rs.js

Errors encountered while trying to parse file
  /path-to-project/node_modules/@silvia-odwyer/photon/photon_rs_bg.wasm
  {:line 1, :column 0, :message "Character '' (U+0000) is not a valid identifier start char"}

The photon_rs_bg.wasm file exists, and permissions are correct.

Can you help us on this matter or propose another better approach to image manipulation with ClojureScript?

1

There are 1 answers

0
Thomas Heller On

shadow-cljs currently does not support bundling .wasm files.

You can setup and use webpack to do the JS/WASM bundling instead via :js-provider :external.