Skip to content
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

Failure to Load Large PNG Images (e.g., 8K Resolution) in Node.js on Windows #84

Open
kyouhei-horizumi opened this issue Nov 9, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@kyouhei-horizumi
Copy link

When attempting to load large images, such as those with 8K resolution, the operation occasionally fails.

OS: Windows 11
Node.js: v22.9.0
wasm-vips: 0.0.11

import Vips from 'wasm-vips';

Vips().then((vips) => {
    const image = vips.Image.newFromFile('nc192085.png');
    image.jpegsave('nc192085.jpg');
}).catch(console.error);
PS > node app.js
rb [vips::Error]: unable to call jpegsave
VipsImage: unable to write to "/tmp/vips-0-3093572251.v"
system error: No such file or directory

    at Fb (file:///.../node_modules/wasm-vips/lib/vips-node.mjs:58:43)
    at me (file:///.../node_modules/wasm-vips/lib/vips-node.mjs:216:270)
    at wasm://wasm/015f49d6:wasm-function[3980]:0x1a22de
    at ue (file:///.../node_modules/wasm-vips/lib/vips-node.mjs:218:356)
    at wasm://wasm/015f49d6:wasm-function[6012]:0x2b8b15
    at me (file:///.../node_modules/wasm-vips/lib/vips-node.mjs:216:270)
    at wasm://wasm/015f49d6:wasm-function[3253]:0x176546
    at he (file:///.../node_modules/wasm-vips/lib/vips-node.mjs:218:38)
    at wasm://wasm/015f49d6:wasm-function[4349]:0x1b9ab4
    at Image.jpegsave (eval at Sh (file:///.../node_modules/wasm-vips/lib/vips-node.mjs:153:241), <anonymous>:7:1) {
  ta: 9375224
}

nc192085.png
nc192085

Notes

  • vips.Image.newFromFile('small.png').jpegsave('small.jpg'); => OK
  • vips-dev-8.16\bin\vips.exe jpegsave nc192085.png nc192085.jpg => OK
  • on WSL2 (Ubuntu 22.04 / Node.js v22.5.1) => OK
@kleisauke kleisauke added the bug Something isn't working label Nov 10, 2024
@kleisauke kleisauke added this to the v0.0.12 milestone Nov 10, 2024
@kleisauke
Copy link
Owner

The Wasm binary is somewhat POSIX-specific, so it doesn't recognize that it's running on a Windows system. By default, it uses the /tmp directory when libvips decompresses a large image (above 100MiB when decompressed) to a temporary file on the disk. You can adjust the threshold for open-via-memory versus open-via-disk using the VIPS_DISC_THRESHOLD environment variable. See for more information:
https://www.libvips.org/API/current/How-it-opens-files.html

To prevent the use of the /tmp directory, you can also set the TMPDIR environment variable to a different path, for example:

preRun: (module) => {
// libvips stores temporary files by default in `/tmp`;
// set the TMPDIR env variable to override this directory
module.ENV.TMPDIR = tmpdir();
}

Alternatively, you can open the image in sequential access mode:

@@ -1,6 +1,8 @@
 import Vips from 'wasm-vips';
 
 Vips().then((vips) => {
-    const image = vips.Image.newFromFile('nc192085.png');
+    const image = vips.Image.newFromFile('nc192085.png', {
+      access: vips.Access.sequential // 'sequential'
+    });
     image.jpegsave('nc192085.jpg');
 }).catch(console.error);

Commit a50ff5e always sets the TMPDIR environment variable to require('os').tmpdir() on Node.js, this will be in v0.0.12. Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants