exif-parser vs image-size vs image-type vs imageinfo
Image Metadata and Size Libraries
exif-parserimage-sizeimage-typeimageinfo

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 Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
exif-parser0229-149 years ago-
image-size02,215378 kB49a year agoMIT
image-type04217.31 kB09 months agoMIT
imageinfo059-414 years ago-

Feature Comparison: exif-parser vs image-size vs image-type vs imageinfo

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-size:

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

  • 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

  • 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-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.

  • 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

  • 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-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.

  • 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

  • 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-size:

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

  • 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

  • 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-size:

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

  • 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: exif-parser vs image-size vs image-type vs imageinfo

  • 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-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.

  • 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 exif-parser

exif-parser

exif-parser is a parser for image metadata in the exif format, the most popular metadata format for jpeg and tiff images. It is written in pure javascript and has no external dependencies. It can also get the size of jpeg images and the size of the jpeg thumbnail embedded in the exif data. It can also extract the embedded thumbnail image.

Installing

npm install exif-parser

You can also build a browser bundle to include it with a <script> tag in a HTML document, like this:

git clone git@github.com:bwindels/exif-parser.git
cd exif-parser/
make build-browser-bundle

Built versions of the bundles are also available in the exif-parser-browser-bundles repo.

This will generate a dist/exif-parser-(version).js and dist/exif-parser-(version)-min.js file. These bundles expose the parser on the ExifParser global variable, which you would use like this:

var parser = window.ExifParser.create(arrayBuffer);

Creating a parser

To start parsing exif data, create a new parser like below. Note that the buffer you pass does not have to be the buffer for the full jpeg file. The exif section of a jpeg file has a maximum size of 65535 bytes and the section seems to always occur within the first 100 bytes of the file. So it is safe to only fetch the first 65635 bytes of a jpeg file and pass those to the parser.

The buffer you pass to create can be a node buffer or a DOM ArrayBuffer.

var parser = require('exif-parser').create(buffer);
var result = parser.parse();

Setting the flags

Before calling parse, you can set a number of flags on the parser, telling it how to behave while parsing.

Add fields in the binary format to result. Since these fields are mostly used for internal fields like Padding, you generally are not interested in these. If enabled, values for these fields will be a Buffer object in node or an ArrayBuffer in DOM environments (browsers).

parser.enableBinaryFields([boolean]), default false;

EXIF tags are organized into different sections, and to tell you the offset to other sections, EXIF uses certain tags. These tags don't tell you anything about the image, but are more for parsers to find out about all tags. Hence, these "pointer" fields are not included in the result tags field by default. Change this flag to include them nonetheless.

parser.enablePointers([boolean]), default false;

Resolve tags to their textual name, making result.tags a dictonary object instead of an array with the tag objects with no textual tag name.

parser.enableTagNames([boolean]), default true;

Read the image size while parsing.

parser.enableImageSize([boolean]), default true;

Read the EXIF tags. Could be useful to disable if you only want to read the image size.

parser.enableReturnTags([boolean]), default true;

EXIF values can be represented in a number of formats (fractions, degrees, arrays, ...) with different precision. Enabling this tries to cast values as much as possible to the appropriate javascript types like number, Date.

parser.enableSimpleValues([boolean]), default true;

working with the result

Getting the tags

the tags that were found while parsing are stored in result.tags unless you set parser.enableReturnTags(false). If parser.enableTagNames is set to true, result.tags will be an object with the key being the tag name and the value being the tag value. If parser.enableTagNames is set to false, result.tags will be an array of objects containing section, type and value properties.

Getting the image size

If parser.enableImageSize is set to true, result.getImageSize() will give you the image size as an object with width and height properties.

Getting the thumbnail

You can check if there is a thumbnail present in the exif data with result.hasThumbnail(). Exif supports thumbnails is jpeg and tiff format, though most are in jpeg format. You can check if there is a thumbnail present in a give format by passing the mime type: result.hasThumbnail("image/jpeg").

You can also get the image size of the thumbnail as an object with width and height properties: result.getThumbnailSize().

To get the node buffer or arraybuffer containing just the thumbnail, call result.getThumbnailBuffer()

Running the unit tests

Install nodeunit globally from npm if you haven't done so already. You can run the tests with nodeunit test/test-*.js.

Contributions

I welcome external contributions through pull requests. If you do so, please don't use regular expressions. I don't like them, and don't want to maintain a project where they are used. Also, when fixing a bug please provide a regression unit test if it makes sense.