How to check an image dimensions using js or node

You can use image-size npm module:

npm install image-size --save

Then can get dimentions like this:

var sizeOf = require('image-size');
var dimensions = sizeOf('./sample.jpg');
console.log(dimensions.width, dimensions.height);

For more information go through image-size documentations


You can use GraphicsMagick or ImageMagick. I recommend GraphicsMagick as it's lot faster.

Install the npm package gm and use like this:

gm = require('gm');

// obtain the size of an image
gm('test.jpg')
.size(function (err, size) {
  if (!err) {
    console.log('width = ' + size.width);
    console.log('height = ' + size.height);
  }
});