Categories
JavaScript Answers

How to get the width and height of an image in Node.js?

Spread the love

To get the width and height of an image in Node.js, we use the image-size package.

For instance, we write

const sizeOf = require("image-size");

sizeOf("images/funny-cats.png", (err, dimensions) => {
  console.log(dimensions.width, dimensions.height);
});

to call the sizeOf function to read the images/funny-cats.png image.

And we get the width and height from the dimensions parameter in the callback.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.