-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deno support #81
Comments
It looks like the generated emscripten code contains an option to specify the content of the wasm binary and then that will be used instead of the location of the file. And I think the signature of the initializeImageMagick(wasmLocationOrData?: string | Uint8Array | Buffer): But I will need to experiment with that and see if that works. And I am wondering if we could combine our efforts and automatically generate the deno library in this project? Not yet sure how we can do then you would not longer need to maintain that library and we can hopefully detect issues earlier. Maybe we could even run the unit tests in deno? |
That would be great and I can help you, if you want. Due the code is written in TypeScript, I propose to make some tweaks in the code so it would work primary on Deno (and browser) and use https://github.com/denoland/dnt to build the Node version. I'm using this strategy in one of my projects and works great (https://github.com/oscarotero/keep-a-changelog/blob/master/build_npm.ts). |
I could use some help with this but I would prefer to go from |
Okay, understood. Deno works very similar to browsers (it uses Web standards as much as possible) but it also has native support for TypeScript. In Node the imported files are resolved magically. For example: import magick from './magick' This can import the file The other thing was to copy the module that had the wasm code, including a ESM export to be imported correctly in Deno (because it was only UMD). In the new versions, this step is broken, because the wasm file is loaded dynamically in the browser environment, which uses If want to know which web standards are supported by Deno, take a look to this cheatsheet (under the Web APIs section). As you can see, only Fetch is supported but there are different ways to instantiate WebAssembly modules. |
I was able to implement loading the Are you aware that the content of the dist folder has changed since version |
I just tried
I would also prefer to use the TypeScript code in Deno, in order to have proper types. I also tried your latest commit on Deno (after transforming the code using my script): console.log("Initialize");
const wasmFile = import.meta.resolve("../deno/src/wasm/magick_native.wasm");
const file = await fetch(wasmFile);
const wasm = await file.arrayBuffer();
await initializeImageMagick(wasm);
console.log("Read");
const data: Uint8Array = await Deno.readFile("test/unsplash.jpg");
await ImageMagick.read(data, async (img: IMagickImage) => {
console.log("crop");
img.crop(1000, 1000);
console.log("resize");
img.resize(200, 100);
console.log("write");
await img.write(
(data: Uint8Array) => Deno.writeFile("test/unsplash-blur.png", data),
MagickFormat.Png,
);
}); And the code seems to work (it read, crop and resize the image) but fails in the
|
I was able to run this project with Your code is failing because I made another breaking change in the |
Okay. I'd rather to use directly the TypeScript code in Deno (for better debugging) but if the mjs file works, that's fine. My version is published on lume.land/x: https://deno.land/x/[email protected]. If you are going to maintain the Deno version, probably I should deprecate this package and create a new one pointing to this repo? Or perhaps it's possible to edit the current package to use this repo. |
Not related with this, but when I try to convert images to AVIF format, the browser cannot display them (tested on Firefox and Chrome). It says the image cannot be shown because it contains errors. |
Not sure how I want to move forward with Deno support. At least I have a proof of concept now on how someone could get it working but a proper module would probably be the right idea. Maybe a separate build step that makes this project available as a module? I cannot reproduce your avif issue. Maybe create a separate discussion for that? And make sure that you are using the latest code on main. I recently fixed a bug in the aom encoder build so that might be causing what you see. |
In deno.land you can register a new module choosing a directory inside a GitHub repo. For example, my version (https://deno.land/x/imagemagick_deno) contains the code inside the Another think is about cache. Deno doesn't have a Edit: I could manage to cache the wasm code using the Web Cache API, that is supported by Deno. Here's the script: And about avif, I'll do more tests and wil open a new issue if I cannot fix it. thanks! Edit: The latest version works fine generating avif formats. 🎉 |
Can I just say thank you to you two for working on this? I'm dying to using imagemagick via wasm + Deno. There is no way I want to call out to a local bin when accepting user file input. |
it seems already work? (by use import {
ImageMagick,
initializeImageMagick,
Magick,
} from "npm:@imagemagick/magick-wasm";
await initializeImageMagick();
console.log(Magick.imageMagickVersion);
const buf = await fetch(new URL("./download.jpeg", import.meta.url)).then((r) =>
r.arrayBuffer()
);
let x = await ImageMagick.read(new Uint8Array(buf), async (img) => {
return { w: img.width, h: img.height };
});
debugger; |
Is your feature request related to a problem? Please describe.
Hi.
First of all, thank for this great library. I have been maintaining a version of this code to work on Deno. You can see the repo here: https://github.com/lumeland/imagemagick-deno
Basically, it's a script to convert the CJS code to ESM and fix some minor issues.
In the latest two versions, the wasm file was moved to a different file. This is a good idea but makes it more difficult to maintain the Deno compatible version. As I can see, the code detects Deno as a Browser environment, so try to load the wasm file using XMLHttpRequest, which is an old API that Deno doesn't support.
Describe the solution you'd like
If the file was loaded using
fetch()
probably it would work on Deno.Describe alternatives you've considered
As an alternative, maybe providing a way to pass directly the wasm content (instead of the file path) in
Uint8Array
(or any other format you consider) would be great. For example:In this way the code would be more portable to other environments (like Deno).
Additional context
No response
The text was updated successfully, but these errors were encountered: