【问题标题】:How to get image resolution data from uploaded image in express? [duplicate]如何从快递上传的图像中获取图像分辨率数据? [复制]
【发布时间】:2013-12-24 20:59:47
【问题描述】:

我正在使用 express 3 制作一个 http 服务器,该服务器将图像上传到指定文件夹中,但我无法在 req 对象中获得图像分辨率。 我尝试查看 req.files 和 req.files.images 和 req.files.headers 但我找不到该信息。 如何获取上传图片的解析。

【问题讨论】:

    标签: node.js express


    【解决方案1】:

    在此处查看解决方案:Opening images on NodeJS and finding out width/height

    var im = require('imagemagick');
    im.identify(req.files.images.path, function(err, features){
      if (err) throw err
       console.log(features)
       // { format: 'JPEG', width: 3904, height: 2622, depth: 8 }
     })
    

    确保您的项目中包含并安装了 imagemagick。

    【讨论】:

    • 我收到 2013 年 12 月 24 日星期二 01:00:25 GMT uncaughtException spawn ENOENT 错误:在 Process.ChildProcess._handle.onexit (child_process) 的 errnoException (child_process.js:980:11) 处生成 ENOENT .js:771:34) 并且我的应用程序退出。无论如何,我从 req.files.image.path 得到“/home/bhanuc/win/winter/crowd-sourcing/public/uploads/56943-nghb7g.jpg”
    • 你需要安装imagick CLI,imagemagick.org/script/binary-releases.php,同样在你的项目目录下运行npm install imagemagick
    • 我们可以在ubuntu中安装它吗?
    • 这将是最简单的,在你的终端运行:sudo apt-get install imagemagick
    • 谢谢!!!你拯救了我的一天:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 2017-08-23
    • 2015-01-09
    • 1970-01-01
    相关资源
    最近更新 更多