【问题标题】:trying to access and manipulate images with node.js and GD or imagemagick尝试使用 node.js 和 GD 或 imagemagick 访问和操作图像
【发布时间】:2011-08-10 21:38:31
【问题描述】:

我正在尝试创建驻留在服务器上的 jpg 的缩略图。我尝试使用 node-gd 和/或 node-imagemagick 但都无法访问该文件:

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 ...");
    }
});

日志:打开文件失败...

imagemagick:

var im = require('imagemagick');
im.identify('./test.jpeg', function (err, features) {
  if (err) throw err;
  console.log(features);
});

日志:错误:命令失败:execvp():没有这样的文件或目录

但 test.jpeg 文件肯定在那里。

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

工作正常!?没有记录错误。

我在 jpeg 上尝试了 chmod 0777。什么都没有。

【问题讨论】:

    标签: node.js imagemagick gd


    【解决方案1】:

    根据我对 node 的 imagemagick 模块文档的理解,该模块提供了对 imagemagick 命令行二进制文件的访问。您是否安装了 imagemagick(命令行二进制文件)?它们在你 shell 的 PATH 中吗?

    您正在寻找一个名为“identify”的二进制文件。您可以通过运行“which identify”来显示它的路径。它应该给你一个完整的路径 - 如果提示刚刚返回,你没有安装它或者它不在你的路径中。

    如果您使用的是 win32,which 命令将无济于事,您必须检查一个名为 identify.exe 的二进制文件。

    (从未与 gd 合作过 - 所以我不确定)

    这是带有您的代码的 imagemagick 示例 - 请注意,在您的环境中识别的路径可能不同:

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

    所以 - 节点模块和您的代码对我有用。

    【讨论】:

    • 太棒了,这对我使用 imagemagick 有帮助。我重新安装了它,它工作。谢谢。 GD 的问题是,当前的节点版本似乎有问题。降级到 0.1.6,它又可以工作了。
    猜你喜欢
    • 1970-01-01
    • 2014-05-18
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 2022-09-27
    相关资源
    最近更新 更多