2

In NodeJS I need to create an API for remote image processing. Using the URL of an image I need to get all the relevant data (width, height, file size,etc) and then process it using a library like Graphics magick. The problem is, that gm always returns this error

{ [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' }

The code I used is

request.get(imageUrl, function (err, res, body) {

   var buffer = new Buffer(body,'binary');

   gm(buffer)
    .size(function (err, size) {
      if (!err) {
        console.log('width = ' + size.width);
        console.log('height = ' + size.height);
      } else
        console.log(err)
    });


});

The question is: How can i process an image without downloading it?

Gigi Ken
  • 23
  • 2

1 Answers1

0

There is no general specification for image meta data across different image file formats. So in most cases, you will have to rely on the remote server's API serving you image meta data without the full image information or - which is the case you want to avoid - just fetch the full image and do the calculation yourself. If you do not need the exact image dimensions or ratio right away, you may estimate them by sending an HTTP HEAD request and interpreting the Content-Type and Content-Length HTTP response headers.

Regarding the ENOENT error, it seems like this could either be about missing data (Is body set correctly?) or a missing ImageMagick installation: Error: spawn ENOENT while using GM in node

Community
  • 1
  • 1
  • I do need the exact image dimensions, so I need to fetch the full image. The body is I have installed both ImageMagick (v 0.1.3) and gm(v 1.9.0) How can I fetch the full image in order to calculate its dimensions? – Gigi Ken Feb 05 '14 at 08:45