Image Metadata and Size Libraries Comparison
image-size vs exif-parser vs image-type vs imageinfo
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.

NPM Package Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
image-size6,146,2732,07156.6 kB315 days agoMIT
exif-parser882,378221-147 years ago-
image-type44,8513737.06 kB02 years agoMIT
imageinfo5,32559-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

A Node module to get dimensions of any image file

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

Programmatic Usage

npm install image-size --save

or

yarn add image-size

Synchronous

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

Asynchronous

const sizeOf = require("image-size")
sizeOf("images/funny-cats.png", function (err, dimensions) {
  console.log(dimensions.width, dimensions.height)
})

NOTE: The asynchronous version doesn't work if the input is a Buffer. Use synchronous version instead.

Also, the asynchronous functions have a default concurrency limit of 100 To change this limit, you can call the setConcurrency function like this:

const sizeOf = require("image-size")
sizeOf.setConcurrency(123456)

Using promises (nodejs 10.x+)

const { promisify } = require("util")
const sizeOf = promisify(require("image-size"))
sizeOf("images/funny-cats.png")
  .then((dimensions) => {
    console.log(dimensions.width, dimensions.height)
  })
  .catch((err) => console.error(err))

Async/Await (Typescript & ES7)

const { promisify } = require("util")
const sizeOf = promisify(require("image-size"))(async () => {
  try {
    const dimensions = await sizeOf("images/funny-cats.png")
    console.log(dimensions.width, dimensions.height)
  } catch (err) {
    console.error(err)
  }
})().then((c) => console.log(c))

Multi-size

If the target file is an icon (.ico) or a cursor (.cur), the width and height will be the ones of the first found image.

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

const sizeOf = require("image-size")
const images = sizeOf("images/multi-size.ico").images
for (const dimensions of images) {
  console.log(dimensions.width, dimensions.height)
}

Using a URL

const url = require("url")
const http = require("http")

const sizeOf = require("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(sizeOf(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

const imageSize = require("image-size")
imageSize.disableTypes(["tiff", "ico"])

Disabling all file-system reads

const imageSize = require("image-size")
imageSize.disableFS(true)

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.

const sizeOf = require("image-size")
const dimensions = sizeOf("images/photo.jpeg")
console.log(dimensions.orientation)

Command-Line Usage (CLI)

npm install image-size --global

or

yarn global add image-size

followed by

image-size image1 [image2] [image3] ...

Credits

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

Contributors