开发者

trying to access and manipulate images with node.js and GD or imagemagick

i'm trying to create a thumbnail of an jpg that resides on the server. i tried using node-gd and/or node-imagemagick but neither could access the file:

var gd = require('node-gd');
gd.openJpeg("./test.jpeg", function (img, path) {
    if (img) {
        console.log("file opened ... " + img);
    }
    else {
        console.log("failed to open file ...");
    }
});

logs: failed to open file ...

imagemagick:

var im = require('imagemagick');
im.identify('./test.jpeg', function (err, features) {
  if (e开发者_StackOverflow中文版rr) throw err;
  console.log(features);
});

logs: Error: Command failed: execvp(): No such file or directory

but the test.jpeg file is definitely there.

var fs = require('fs');
fs.open(filePath, 'r', function (err, fd) {
    console.log("open file ... " + err + " " + fd);
});

works fine!? no error is logged.

i tried chmod 0777 on the jpeg. nothing.


From what I understand of the documentation of the imagemagick module for node is, that the module provides access to the comandline binaries of imagemagick. Do you have imagemagick (the commandline binaries) installed? Are they in the PATH of you shell?

You are looking for a binary named "identify". You can show the path to it by running "which identify". It should give you a full path - if the prompt just returns, you don't have it installed or it's not in your path.

If you are on win32 the which command won't help, you have to check for a binary called identify.exe.

(never worked with gd - so I am unsure there)

here is the imagemagick example with your code - please note, the path to identify may be different in your environment:

snowflake:Desktop rhaen$ node check_im.js 
{ format: 'JPEG', width: 320, height: 250, depth: 8 }
snowflake:Desktop rhaen$ which identify
/usr/local/bin/identify

So - the node module and your code works for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜