Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node get image properties (height, width)

I'm looking for a means to get the height and width of images from a given path locally. I know about imagemagick and graphicmagick but I'd prefer a method that doesn't involve installing extra software to the OS. If I can keep it to node modules that would be fantastic.

Does anyone have any ideas that may help me?

Worst case scenario, I'll use IM and GM but like it said would prefer to avoid this path.

like image 764
David Avatar asked Mar 29 '13 02:03

David


2 Answers

You can use JIMP(JavaScript Image Manipulation Program). An image processing library for Node written entirely in JavaScript, with zero external or native dependencies. It has so many other image manipulation options available if you want.

var Jimp = require('jimp');
var image = new Jimp("./path/to/image.jpg", function (err, image) {
    var w = image.bitmap.width; //  width of the image
    var h = image.bitmap.height; // height of the image
});

Hope this will help.

like image 194
Nitin Bhapkar Avatar answered Sep 21 '22 21:09

Nitin Bhapkar


You can use a pure JS node module https://www.npmjs.org/package/image-size .. doesn't require installing anything extra

var sizeOf = require('image-size');
var dimensions = sizeOf('images/funny-cats.png');
console.log(dimensions.width, dimensions.height);
like image 27
NetRoY Avatar answered Sep 21 '22 21:09

NetRoY