Gathering detailed insights and metrics for image-type
Gathering detailed insights and metrics for image-type
Gathering detailed insights and metrics for image-type
Gathering detailed insights and metrics for image-type
npm install image-type
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (64.75%)
TypeScript (35.25%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
408 Stars
55 Commits
16 Forks
9 Watchers
1 Branches
7 Contributors
Updated on Jul 05, 2025
Latest Version
6.0.0
Package Id
image-type@6.0.0
Unpacked Size
7.13 kB
Size
2.87 kB
File Count
5
NPM Version
10.9.2
Node Version
20.19.1
Published on
May 20, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
5
Detect the image type of an ArrayBuffer/Uint8Array
See the file-type
module for more file types and a CLI.
1npm install image-type
1import {readChunk} from 'read-chunk'; 2import imageType, {minimumBytes} from 'image-type'; 3 4const buffer = await readChunk('unicorn.png', {length: minimumBytes}); 5 6await imageType(buffer); 7//=> {ext: 'png', mime: 'image/png'}
Or from a remote location:
1import https from 'node:https'; 2import imageType, {minimumBytes} from 'image-type'; 3 4const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg'; 5 6https.get(url, response => { 7 response.on('readable', () => { 8 (async () => { 9 const chunk = response.read(minimumBytes); 10 response.destroy(); 11 console.log(await imageType(chunk)); 12 //=> {ext: 'jpg', mime: 'image/jpeg'} 13 })(); 14 }); 15});
1const xhr = new XMLHttpRequest(); 2xhr.open('GET', 'unicorn.png'); 3xhr.responseType = 'arraybuffer'; 4 5xhr.onload = () => { 6 (async () => { 7 await imageType(new Uint8Array(this.response)); 8 //=> {ext: 'png', mime: 'image/png'} 9 })(); 10}; 11 12xhr.send();
Returns an Promise<object>
with:
ext
- One of the supported file typesmime
- The MIME typeOr undefined
when there is no match.
Type: ArrayBuffer | Uint8Array
It only needs the first minimumBytes
amount of bytes.
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.
jpg
png
gif
webp
flif
cr2
tif
bmp
jxr
psd
ico
bpg
jp2
- JPEG 2000jpm
- JPEG 2000jpx
- JPEG 2000heic
cur
dcm
- DICOM Image FileSVG isn't included as it requires the whole file to be read, but you can get it here.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 6/30 approved changesets -- score normalized to 2
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More