Open Source JavaScript Library for Image Processing

JavaScript API for detecting image dimensions

What is Image-Size?

Image-Size is a very simple light-weight image processing library that enables software developers to get dimensions of images at run time. The API supports a wide range of image formats and you can get dimensions of most of the popular file formats using the API. The API provides a synchronous and asynchronous method for working with the images. The asynchronous functions have a default concurrency limit of 100 and in order to change this limit, you can manually change concurrency. Furthermore, the asynchronous version doesn't work if the input is a Buffer and you'll have to use the asynchronous method instead.

Previous Next

Getting Started with Image-Size

The recommended way to install Image-Size via NPM. Please use the following command to install it.

Install Image-Size Thief via NPM

 npm install image-size --global 

Get Image Dimensions via Free JavaScript API

The open-source Image-Size library allows JavaScript developers to get dimensions of the images programmatically. In order to get dimensions from an image, the API provides sizeOf() method. By using the following two lines of code, you can easily get the dimensions of the image.

Get Image Dimensions

  1. Load Image-Size Library
  2. Get dimensions using sizeOf() method and pass image path as string
  3. Get width of image using dimensions.width and height using dimensions.height

Get image dimensions in JavaScript

const sizeOf = require('image-size')
const dimensions = sizeOf('images/funny-cats.png')
console.log(dimensions.width, dimensions.height)