Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  167] [ 3]  / answers: 1 / hits: 20211  / 7 Years ago, thu, october 12, 2017, 12:00:00

So I have a sample.jpg file and I want to check its dimensions.


The desired logic goes like this:


var img = require('./sample.jpg');
console.log(typeof img) // returns string -> Image
console.log(img.height) // returns number -> 300
console.log(img.width) // returns nubmer -> 250

Never mind the return of the typeof. I just wan't to get the dimensions. But that is the simple break down of what where I am going. Is there a way to do this using node or plain js?


More From » node.js

 Answers
17

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


[#56241] Tuesday, October 10, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ingridmikaylam

Total Points: 93
Total Questions: 81
Total Answers: 105

Location: Nicaragua
Member since Tue, Dec 8, 2020
4 Years ago
;