image-size vs exif-parser vs image-type vs imageinfo
Image Metadata and Size Libraries Comparison
1 Year
image-sizeexif-parserimage-typeimageinfo
What's Image Metadata and Size Libraries?

These npm packages are designed to assist developers in extracting and handling image metadata, dimensions, and types. They simplify the process of working with images by providing straightforward APIs to access essential information such as EXIF data, image dimensions, and file types. This functionality is crucial for applications that require image processing, validation, or display, enhancing user experience and ensuring proper handling of image files.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
image-size12,075,3052,098378 kB296 days agoMIT
exif-parser1,414,473222-148 years ago-
image-type80,1413737.06 kB02 years agoMIT
imageinfo8,55759-413 years ago-
Feature Comparison: image-size vs exif-parser vs image-type vs imageinfo

Metadata Extraction

  • image-size:

    image-size does not extract metadata but focuses on retrieving image dimensions, making it less suitable for applications needing detailed metadata extraction.

  • exif-parser:

    exif-parser specializes in extracting EXIF metadata from JPEG images, providing detailed information such as camera model, exposure settings, and GPS coordinates. It is tailored for applications that need to leverage this data for sorting, filtering, or displaying images based on their metadata.

  • image-type:

    image-type identifies the MIME type of an image based on its binary signature, but it does not provide any metadata beyond that, making it limited in this regard.

  • imageinfo:

    imageinfo provides a broader set of information, including dimensions and file type, but it may not delve deeply into EXIF metadata like exif-parser.

Performance

  • image-size:

    image-size is highly efficient, as it reads only the necessary bytes from the image file to determine dimensions, ensuring minimal memory usage and quick responses, ideal for validating images before upload.

  • exif-parser:

    exif-parser is optimized for performance when parsing EXIF data, allowing for fast extraction of metadata without loading the entire image, making it suitable for applications that process large batches of images.

  • image-type:

    image-type is lightweight and fast, as it inspects only the header of the image file to determine its type, which is efficient for applications that need quick file type validation.

  • imageinfo:

    imageinfo may be slower than the others due to its comprehensive analysis, but it provides a complete overview of the image, making it suitable for applications that require detailed information.

Supported Formats

  • image-size:

    image-size supports a wide range of image formats, including JPEG, PNG, GIF, and more, making it versatile for applications that handle various image types.

  • exif-parser:

    exif-parser primarily supports JPEG images, which limits its use for applications dealing with other image formats that may not contain EXIF data.

  • image-type:

    image-type can identify multiple image formats based on binary signatures, making it a flexible choice for applications that need to support diverse image types.

  • imageinfo:

    imageinfo also supports various formats, but its performance may vary depending on the complexity of the image and the amount of data being analyzed.

Ease of Use

  • image-size:

    image-size offers a simple interface for obtaining image dimensions, making it user-friendly for developers needing quick size checks.

  • exif-parser:

    exif-parser has a straightforward API for extracting EXIF data, making it easy to integrate into projects that require image metadata extraction.

  • image-type:

    image-type provides a very simple API for determining image types, making it easy to implement in applications requiring file type validation.

  • imageinfo:

    imageinfo has a more complex API due to its comprehensive nature, which may require additional handling but provides a wealth of information in return.

Use Cases

  • image-size:

    image-size is perfect for web applications that need to validate image sizes before upload or display, ensuring images meet specific criteria.

  • exif-parser:

    exif-parser is ideal for applications focused on photography, image organization, or any project that requires detailed image metadata for sorting or filtering.

  • image-type:

    image-type is best suited for applications that require quick validation of image types to prevent unsupported formats from being processed.

  • imageinfo:

    imageinfo is suitable for applications that need a complete overview of image files, such as galleries or image management systems that require both dimensions and type.

How to Choose: image-size vs exif-parser vs image-type vs imageinfo
  • image-size:

    Select image-size if your primary requirement is to quickly obtain the dimensions of various image formats without loading the entire image into memory. This package is efficient for validating image sizes before processing or uploading.

  • exif-parser:

    Choose exif-parser if you need to extract detailed EXIF metadata from JPEG images, such as camera settings, orientation, and geolocation data. It is particularly useful for applications that require in-depth image analysis or organization based on metadata.

  • image-type:

    Opt for image-type when you need to determine the MIME type of an image file based on its binary data. This is essential for applications that require file type validation or need to support multiple image formats dynamically.

  • imageinfo:

    Use imageinfo if you require a comprehensive analysis of image files, including dimensions, file type, and additional metadata. This package is suitable for applications that need a broader range of image information in a single call.

README for image-size

image-size

Build Status Package Version Downloads

Fast, lightweight NodeJS package to get dimensions of any image file or buffer.

Key Features

  • Zero dependencies
  • Supports all major image formats
  • Works with both files and buffers
  • Minimal memory footprint - reads only image headers
  • ESM and CommonJS support
  • TypeScript types included

Supported formats

  • BMP
  • CUR
  • DDS
  • GIF
  • HEIC (HEIF, AVCI, AVIF)
  • ICNS
  • ICO
  • J2C
  • JPEG-2000 (JP2)
  • JPEG
  • JPEG-XL
  • KTX (1 and 2)
  • PNG
  • PNM (PAM, PBM, PFM, PGM, PPM)
  • PSD
  • SVG
  • TGA
  • TIFF
  • WebP

Installation

npm install image-size
# or
yarn add image-size
# or
pnpm add image-size

Usage

Passing in a Buffer/Uint8Array

Best for streams, network requests, or when you already have the image data in memory.

import { imageSize } from 'image-size'
// or
const { imageSize } = require('image-size')

const dimensions = imageSize(buffer)
console.log(dimensions.width, dimensions.height)

Reading from a file

Best for local files. Returns a promise.

import { imageSizeFromFile } from 'image-size/fromFile'
// or
const { imageSizeFromFile } = require('image-size/fromFile')

const dimensions = await imageSizeFromFile('photos/image.jpg')
console.log(dimensions.width, dimensions.height)

Note: Reading from files has a default concurrency limit of 100 To change this limit, you can call the setConcurrency function like this:

import { setConcurrency } from 'image-size/fromFile'
// or
const { setConcurrency } = require('image-size/fromFile')
setConcurrency(123456)

3. Command Line

Useful for quick checks.

npx image-size image1.jpg image2.png

Multi-size

If the target file/buffer is an HEIF, an ICO, or a CUR file, the width and height will be the ones of the largest image in the set.

An additional images array is available and returns the dimensions of all the available images

import { imageSizeFromFile } from 'image-size/fromFile'
// or
const { imageSizeFromFile } = require('image-size/fromFile')

const { images } = await imageSizeFromFile('images/multi-size.ico')
for (const dimensions of images) {
  console.log(dimensions.width, dimensions.height)
}

Using a URL

import url from 'node:url'
import http from 'node:http'
import { imageSize } from 'image-size'

const imgUrl = 'http://my-amazing-website.com/image.jpeg'
const options = url.parse(imgUrl)

http.get(options, function (response) {
  const chunks = []
  response
    .on('data', function (chunk) {
      chunks.push(chunk)
    })
    .on('end', function () {
      const buffer = Buffer.concat(chunks)
      console.log(imageSize(buffer))
    })
})

You can optionally check the buffer lengths & stop downloading the image after a few kilobytes. You don't need to download the entire image

Disabling certain image types

import { disableTypes } from 'image-size'
// or
const { disableTypes } = require('image-size')

disableTypes(['tiff', 'ico'])

JPEG image orientation

If the orientation is present in the JPEG EXIF metadata, it will be returned by the function. The orientation value is a number between 1 and 8 representing a type of orientation.

import { imageSizeFromFile } from 'image-size/fromFile'
// or
const { imageSizeFromFile } = require('image-size/fromFile')

const { width, height, orientation } = await imageSizeFromFile('images/photo.jpeg')
console.log(width, height, orientation)

Limitations

  1. Partial File Reading

    • Only reads image headers, not full files
    • Some corrupted images might still report dimensions
  2. SVG Limitations

    • Only supports pixel dimensions and viewBox
    • Percentage values not supported
  3. File Access

    • Reading from files has a default concurrency limit of 100
    • Can be adjusted using setConcurrency()
  4. Buffer Requirements

    • Some formats (like TIFF) require the full header in buffer
    • Streaming partial buffers may not work for all formats

License

MIT

Credits

not a direct port, but an attempt to have something like dabble's imagesize as a node module.

Contributors