Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

image-dimensions-stream

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-dimensions-stream

Get image dimensions from stream

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

image-dimensions-stream

A Node module to get dimensions of any image file stream

Supported formats

  • BMP
  • GIF
  • JPEG
  • PNG
  • PSD
  • DDS

Upcoming

  • SWF
  • CUR
  • ICO
  • ICNS
  • TIFF
  • WebP
  • SVG

Programmatic Usage

yarn add image-dimensions-stream

Example

const ImageDimensionsStream = require('image-dimensions-stream');
const pipeline = util.promisify(require('stream').pipeline);

async function main() {
  const sizeStream = new ImageDimensionsStream();
  let result = {
    mime: null,
    dimensions: null,
  };

  sizeStream.on('mime', (mime) => {
    console.log('mime:', mime);
    result.mime = mime;
  });

  sizeStream.on('dimensions', (dimensions) => {
    console.log('dimensions:', dimensions);
    result.dimensions = dimensions;
  });

  await pipeline(fs.createReadStream('images/funny-cats.png'), sizeStream, fs.createWriteStream('/dev/null'));

  return result;
}

main().then(console.log).catch(console.error);

Options

KeyTypeDefaultDescription
requireMimeboolean functiontruedestroy stream if mime can't be found
requireDimensionsboolean functiontruedestroy stream if dimensions can't be found
exifboolean functionfalseuse EXIF (Orientation) data if available
requireValidExifboolean functionfalsedestroy stream on invalid EXIF data otherwise just skip EXIF block. Only useful if exif option returns true
maxMimeChunkOffsetnumberMinimum value possibleWhether to destroy the stream if we couldn't detect mime type after reading this amount of bytes
maxMimeBufferSizenumber in bytes4100Maximum buffer size when detecting mime type
maxDimensionsBufferSizenumber in bytes64000Maximum buffer size when detecting dimensions

Credits

image-size for test images and file structures

Keywords

FAQs

Package last updated on 15 Jun 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc