Skip to content

How to get an image width and height using Node

FULL-STACK WEB DEVELOPMENT BOOTCAMP

2024 COHORT SIGNUPS END TOMORROW

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
  • Learn modern web development in my BOOTCAMP (SIGNUP END TOMORROW FEB 20, 2024)
  • THE VALLEY OF CODE (+ PRO), your web development manual
  • I wrote 15+ coding BOOKS, all available in THE VALLEY OF CODE PRO
  • Indie solopreneur internet business masterclass SOLO LAB (summer 2024)