<commit_before># image-type [![Build Status](https://travis-ci.org/sindresorhus/image-type.svg?branch=master)](https://travis-ci.org/sindresorhus/image-type)

> Detect the image type of a Buffer/Uint8Array

See the [`file-type`](https://github.com/sindresorhus/file-type) module for more file types and a CLI.


## Install

```
$ npm install image-type
```


## Usage

##### Node.js

```js
const readChunk = require('read-chunk');
const imageType = require('image-type');

const buffer = readChunk.sync('unicorn.png', 0, 12);

imageType(buffer);
//=> {ext: 'png', mime: 'image/png'}
```

Or from a remote location:

```js
const http = require('http');
const imageType = require('image-type');

const url = 'https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif';

http.get(url, response => {
	response.on('readable', () => {
		const chunk = response.read(imageType.minimumBytes);
		response.destroy();
		console.log(imageType(chunk));
		//=> {ext: 'gif', mime: 'image/gif'}
	});
});
```

##### Browser

```js
const xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.png');
xhr.responseType = 'arraybuffer';
<commit_msg>Fix readme usage example (#12)<commit_after># image-type [![Build Status](https://travis-ci.org/sindresorhus/image-type.svg?branch=master)](https://travis-ci.org/sindresorhus/image-type)

> Detect the image type of a Buffer/Uint8Array

See the [`file-type`](https://github.com/sindresorhus/file-type) module for more file types and a CLI.


## Install

```
$ npm install image-type
```


## Usage

##### Node.js

```js
const readChunk = require('read-chunk');
const imageType = require('image-type');

const buffer = readChunk.sync('unicorn.png', 0, 12);

imageType(buffer);
//=> {ext: 'png', mime: 'image/png'}
```

Or from a remote location:

```js
const https = require('https');
const imageType = require('image-type');

const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';

https.get(url, response => {
	response.on('readable', () => {
		const chunk = response.read(imageType.minimumBytes);
		response.destroy();
		console.log(imageType(chunk));
		//=> {ext: 'jpg', mime: 'image/jpeg'}
	});
});
```

##### Browser

```js
const xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.png');
xhr.responseType = 'arraybuffer';

{'fraction_non_alphanumeric': 0.202365308804205, 'fraction_numerical': 0.0056942619360490585, 'mean_word_length': 4.7969543147208125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1001035', 'n_tokens_mistral': 845, 'n_tokens_neox': 792, 'n_words': 168}