Comments (7)
HI @andilem @silvia-odwyer I made a vite build example, please check.
Demo:
http://github.nshen.net/photon-vite/
Code:
https://github.com/nshen/photon-vite
I just forked photon and republished a npm package with wasm-pack build --target web
https://www.npmjs.com/package/photon-web
with vite-plugin-wasm-pack , it works.
from photon.
The problem comes from wasm-bindgen, the way it packages wasm causes all sorts of problems. Even when you do target web. I had to rework the whole package in order to get something working. Hopefully I will have some free time this winter to submit some PRs to wasm-bindgen.
from photon.
@nshen Thanks very much for this, it'll be incredibly useful for those who wish to use Photon with vite
from photon.
@behunin Hi Levi, could you show the code used and I'll take a look at it! Thanks
from photon.
function resize() {
const ctx = small.value.getContext("2d");
ctx.drawImage(orig.value, 0, 0);
try {
import("@silvia-odwyer/photon")
.then((photon) => {
let img = photon.open_image(small.value, ctx);
photon.resize(img, 50, 50, 1);
photon.putImageData(small.value, ctx, img);
})
.catch((e) => {
console.log(e);
});
} catch (e) {
console.log(e);
}
}
This is inside a Vue 3 setup function.
small is a ref to the <canvas>
orig is a ref to the <img />
I get the same error whether I use references or getElementById()
Thank you for your time!
from photon.
I am getting the same (or a similar) error when using Vite (https://vitejs.dev) as build tool.
The problem seems to come from the fact that Vite uses the following WASM import mechanism: https://vitejs.dev/guide/features.html#webassembly. But in photon_rs_bg.js
, the WASM import is defined as import * as wasm from './photon_rs_bg.wasm';
, which doesn't work with Vite WASM import.
I found no easy solution, even copying the whole package in my repo and editing the import only led to a new error:
Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #0 module="./photon_rs_bg.js" error: module is not an object or function
Inspection of the .wasm showed that there are indeed imports from ./photon_rs_bg.js
.
Being no JS/WASM expert, I have no idea how to solve this. Is it required to build the WASM with another type, like web
(https://rustwasm.github.io/docs/wasm-bindgen/reference/deployment.html)?
@silvia-odwyer Could you tell us if you plan to support Vite or if you have any idea how to approach or work around this issue?
from photon.
@andilem Thanks for letting me know about this! I'd recommend opening an issue in the wasm-bindgen repository, as the WASM version of photon is built using it, so it's definitely worth letting them know also, and you'll be able to get it working with Vite in the future hopefully then
from photon.
Related Issues (20)
- What about rotation? HOT 1
- Website: Uncaught TypeError: e.oil is not a function HOT 2
- Many Filters Skip The Last Pixel - Tested with PNGs HOT 4
- photon-node crashes when reading rainbow-pinwheel.jpg HOT 3
- Question: Writing out to different formats HOT 1
- open_image for panorama images on Safari throws InvalidStateError
- Why is there such a big difference in the processing time between photon_rs and photon? HOT 3
- Possibly flawed implementation of image blending HOT 6
- Uncaught RuntimeError: unreachable in Node on multiple functions HOT 7
- Compressing Image HOT 4
- Cloudflare Workers Tutorial Boilerplate WASM WASI HOT 3
- Speed issue with pure rust usage HOT 3
- Some filters are not working HOT 1
- How to use `open_image_from_bytes`? HOT 3
- Use without wasm HOT 4
- Watermark with opacity HOT 1
- Pixel Byte vs Bytes HOT 1
- web workers ? HOT 1
- Question: Any workflow to work with stereo image pairs?
- Can use photon with 16 bit grayscale images?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from photon.