# image-type

> Detect the image type of an ArrayBuffer/Uint8Array

Latest version **6.1.0** (published 2026-03-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install image-type
pnpm add image-type
yarn add image-type
bun add image-type
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.1.0 |
| Published | 2026-03-24 |
| First published | 2014-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 1 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | image, picture, photo, type, detect, check, is, exif, binary, buffer, uint8array, png, jpg, jpeg, gif, webp, tif, bmp, jxr, psd, mime |

## Links

- npm: https://www.npmjs.com/package/image-type
- Repository: https://github.com/sindresorhus/image-type
- Homepage: https://github.com/sindresorhus/image-type#readme
- Issues: https://github.com/sindresorhus/image-type/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/image-type

## Dependencies (1)

- [file-type](https://npm.io/package/file-type.md) ^21.3.4

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 6.1.0 (latest) — 2026-03-24
- 6.0.0 — 2025-05-20
- 5.2.0 — 2023-01-15
- 5.1.0 — 2022-09-24
- 5.0.0 — 2022-07-29
- 4.1.0 — 2019-04-06
- 4.0.0 — 2019-03-06
- 3.1.0 — 2019-03-06
- 3.0.0 — 2017-01-19
- 2.1.0 — 2015-10-11
- 2.0.2 — 2015-02-16
- 2.0.1 — 2014-12-19
- 2.0.0 — 2014-12-19
- 1.1.0 — 2014-10-29
- 1.0.0 — 2014-08-14
- … 5 more at https://npm.io/package/image-type/versions

## README

# image-type

> Detect the image type of an ArrayBuffer/Uint8Array

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

## Install

```sh
npm install image-type
```

## Usage

##### Node.js

```js
import {readChunk} from 'read-chunk';
import imageType, {minimumBytes} from 'image-type';

const buffer = await readChunk('unicorn.png', {length: minimumBytes});

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

Or from a remote location:

```js
import https from 'node:https';
import imageType, {minimumBytes} from 'image-type';

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

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

##### Browser

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

xhr.onload = () => {
	(async () => {
		await imageType(new Uint8Array(this.response));
		//=> {ext: 'png', mime: 'image/png'}
	})();
};

xhr.send();
```

## API

### imageType(input)

Returns an `Promise<object>` with:

- `ext` - One of the [supported file types](#supported-file-types)
- `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)

Or `undefined` when there is no match.

#### input

Type: `ArrayBuffer | Uint8Array`

It only needs the first `minimumBytes` amount of bytes.

### minimumBytes

Type: `number`

The minimum amount of bytes needed to detect a file type. Currently, it's 4100 bytes, but it can change, so don't hardcode it.

## Supported file types

- [`jpg`](https://en.wikipedia.org/wiki/JPEG)
- [`png`](https://en.wikipedia.org/wiki/Portable_Network_Graphics)
- [`gif`](https://en.wikipedia.org/wiki/GIF)
- [`webp`](https://en.wikipedia.org/wiki/WebP)
- [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format)
- [`cr2`](https://fileinfo.com/extension/cr2)
- [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format)
- [`bmp`](https://en.wikipedia.org/wiki/BMP_file_format)
- [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR)
- [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format)
- [`ico`](https://en.wikipedia.org/wiki/ICO_(file_format))
- [`bpg`](https://bellard.org/bpg/)
- [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
- [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
- [`jpx`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
- [`heic`](https://nokiatech.github.io/heif/technical.html)
- [`cur`](https://en.wikipedia.org/wiki/ICO_(file_format))
- [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image File

*SVG isn't included as it requires the whole file to be read, but you can get it [here](https://github.com/sindresorhus/is-svg).*

## Related

- [file-type](https://github.com/sindresorhus/file-type) - Detect the type of a file
- [image-dimensions](https://github.com/sindresorhus/image-dimensions) - Get the dimensions of an image

---
_Source: https://npm.io/package/image-type · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
