How to get an image width and height using Node
New Courses Coming Soon
Join the waiting lists
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)
→ Get my Node.js Handbook
→ Read my
Node.js Tutorial
on The Valley of Code
Here is how can I help you:
- COURSES where I teach everything I know
- CODING BOOTCAMP cohort course - next edition in 2025
- BOOKS 16 coding ebooks you can download for free on JS Python C PHP and lots more
- Follow me on X