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

image-type

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-type

Detect the image type of a Buffer/Uint8Array

  • 0.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61K
decreased by-3.05%
Maintainers
1
Weekly downloads
 
Created
Source

image-type Build Status

Detect the image type of a Buffer/Uint8Array

See the file-type module for more file types.

Install

$ npm install --save image-type
$ bower install --save image-type
$ component install sindresorhus/image-type

Usage

Node.js
var readChunk = require('read-chunk'); // npm install read-chunk
var imageType = require('image-type');
var buffer = readChunk('unicorn.png', 0, 12);

imageType(buffer);
//=> png
Browser
var xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.png');
xhr.responseType = 'arraybuffer';

xhr.onload = function () {
	imageType(new Uint8Array(this.response));
	//=> png
};

xhr.send();

API

imageType(buffer)

Returns: png, jpg, gif, webp, tif, bmp, jxr, psd, false

buffer

Type: buffer (Node.js), uint8array

It only needs the first 12 bytes.

CLI

$ npm install --global image-type
$ image-type --help

Usage
  $ cat <filename> | image-type
  $ image-type <filename>

Example
  $ cat unicorn.png | image-type
  png

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 26 Apr 2014

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