šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

image-size

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-size

get dimensions of any image file

2.0.2
latest
Source
npm
Version published
Weekly downloads
11M
-11.39%
Maintainers
1
Weekly downloads
Ā 
Created

What is image-size?

The image-size npm package is a module that provides a simple API to determine the dimensions of an image file. It supports a variety of image formats, including but not limited to JPEG, PNG, GIF, BMP, and WebP. The package can be used in both synchronous and asynchronous contexts and can handle local files as well as remote images via URLs.

What are image-size's main functionalities?

Synchronous image size retrieval

This feature allows you to synchronously get the dimensions of an image by providing the path to the image file.

const sizeOf = require('image-size');
const dimensions = sizeOf('path/to/image.jpg');
console.log(dimensions.width, dimensions.height);

Asynchronous image size retrieval

This feature allows you to asynchronously get the dimensions of an image by providing the path to the image file and a callback function.

const sizeOf = require('image-size');
sizeOf('path/to/image.jpg', (err, dimensions) => {
  if (err) throw err;
  console.log(dimensions.width, dimensions.height);
});

Image size retrieval from a buffer

This feature allows you to get the dimensions of an image from a buffer, which is useful when you have the image data in memory rather than stored in a file.

const sizeOf = require('image-size');
const fs = require('fs');

fs.readFile('path/to/image.jpg', (err, data) => {
  if (err) throw err;
  const dimensions = sizeOf(data);
  console.log(dimensions.width, dimensions.height);
});

Other packages similar to image-size

Keywords

image

FAQs

Package last updated on 02 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts