Skip to content
FLAVIO COPES
flaviocopes.com
2026

How to get an image width and height using Node

By Flavio Copes

Learn how to get an image width and height in Node.js using the image-size npm module and its sizeOf() function, which reads the file from its location.

~~~

You need to know the location on file system of the image.

If it’s an image from the Internet you can save it to the system tmp folder.

Then install the image-size npm module

npm install image-size

and you can use it like this:

import sizeOf from 'image-size'

const { height, width } = sizeOf(fileLocation)
Tagged: Node.js · All topics
~~~

Related posts about node: