denoland / denoland/image-resizing-api
runtime has escaped from the event loop unexpectedly: event loop error while evaluating the module: TypeError: Invalid URL: 'magick.wasm'
- Dominant language
- TypeScript
- Stars
- 24
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
Using an updated import:
```js
import {
ImageMagick,
initializeImageMagick,
MagickGeometry,
} from "https://deno.land/x/imagemagick_deno@0.0.31/mod.ts";
```
is returning the error "runtime has escaped from the event loop unexpectedly: event loop error while evaluating the module: TypeError: Invalid URL: 'magick.wasm'"
Apparently, magick.wasm is a file included with the ImageMagick library but the method for reading the file is not working. I've found that using the `npm:` gives better results:
```js
import {
ImageMagick,
initializeImageMagick,
MagickFormat,
} from "npm:@imagemagick/magick-wasm@0.0.30"
let wasmInit: Promise | null = null
async function ensureMagickInited() {
if (!wasmInit) {
// kick off the one‐time load+init
wasmInit = (async () => {
const wasmBytes = await Deno.readFile(
new URL(
"magick.wasm",
import.meta.resolve("npm:@imagemagick/magick-wasm@0.0.30"),
),
)
await initializeImageMagick(wasmBytes)
})();
}
await wasmInit
}
async function resizeImage(req: Request) {
await ensureMagickInited()
// your resizing code here
}
```
FWIW, so far I've been unable to get this code (or any of the other myriad approaches) to work, at all. The Edge Function runtime craps out with errors like `CPU time hard limit reached` or `early termination has been triggered` or `CPU time soft limit reached` or `memory limit reached for the worker`.
## References
- https://github.com/supabase/supabase/blob/226d05fb83415be92021008b4ecc81f212be9288/examples/edge-functions/supabase/functions/image-manipulation/index.ts
- https://supabase.com/docs/guides/functions/examples/image-manipulation
- https://github.com/dlemstra/magick-wasm/blob/main/deno/example.ts
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.