{"name":"image-type","version":"6.0.0","keywords":["image","picture","photo","type","detect","check","is","exif","binary","buffer","uint8array","png","jpg","jpeg","gif","webp","tif","bmp","jxr","psd","mime"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"image-type@6.0.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/image-type#readme","bugs":{"url":"https://github.com/sindresorhus/image-type/issues"},"dist":{"shasum":"68a9ee921393db5b5737e15c242532d06d531528","tarball":"http://registry-npm.ywwl.com/image-type/download/image-type-6.0.0.tgz","fileCount":5,"integrity":"sha512-efpcYd/E9A7a+oanft11ceIbO9Aw0iszfJ7Qfh4QLWl2Ulsth9nnllV/L1TmzKwlQ2O5FuT08vy5zxLnGxZe8w==","signatures":[{"sig":"MEUCIFr+OzzsXLHGM/sTS9/PhkVgdoXRRNLHJlTmlOgXtjqdAiEAkGaNqj4lb2x8353pYuNSMwfWeDnbW5RgRiMxcIvPIgs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7306,"size":2936,"noattachment":false,"key":"/image-type/-/image-type-6.0.0.tgz"},"type":"module","types":"./index.d.ts","engines":{"node":">=20"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"94741b2afee0ae1d005609746d8295b25d608b8f","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/image-type.git","type":"git"},"_npmVersion":"10.9.2","description":"Detect the image type of an ArrayBuffer/Uint8Array","directories":{},"sideEffects":false,"_nodeVersion":"20.19.1","dependencies":{"file-type":"^20.5.0"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.60.0","ava":"^6.3.0","tsd":"^0.32.0","read-chunk":"^5.0.0","@types/node":"^22.15.19"},"_npmOperationalInternal":{"tmp":"tmp/image-type_6.0.0_1747738094575_0.8035054126120702","host":"s3://npm-registry-packages-npm-production"},"readme":"# image-type\n\n> Detect the image type of an ArrayBuffer/Uint8Array\n\nSee the [`file-type`](https://github.com/sindresorhus/file-type) module for more file types and a CLI.\n\n## Install\n\n```sh\nnpm install image-type\n```\n\n## Usage\n\n##### Node.js\n\n```js\nimport {readChunk} from 'read-chunk';\nimport imageType, {minimumBytes} from 'image-type';\n\nconst buffer = await readChunk('unicorn.png', {length: minimumBytes});\n\nawait imageType(buffer);\n//=> {ext: 'png', mime: 'image/png'}\n```\n\nOr from a remote location:\n\n```js\nimport https from 'node:https';\nimport imageType, {minimumBytes} from 'image-type';\n\nconst url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';\n\nhttps.get(url, response => {\n\tresponse.on('readable', () => {\n\t\t(async () => {\n\t\t\tconst chunk = response.read(minimumBytes);\n\t\t\tresponse.destroy();\n\t\t\tconsole.log(await imageType(chunk));\n\t\t\t//=> {ext: 'jpg', mime: 'image/jpeg'}\n\t\t})();\n\t});\n});\n```\n\n##### Browser\n\n```js\nconst xhr = new XMLHttpRequest();\nxhr.open('GET', 'unicorn.png');\nxhr.responseType = 'arraybuffer';\n\nxhr.onload = () => {\n\t(async () => {\n\t\tawait imageType(new Uint8Array(this.response));\n\t\t//=> {ext: 'png', mime: 'image/png'}\n\t})();\n};\n\nxhr.send();\n```\n\n## API\n\n### imageType(input)\n\nReturns an `Promise<object>` with:\n\n- `ext` - One of the [supported file types](#supported-file-types)\n- `mime` - The [MIME type](https://en.wikipedia.org/wiki/Internet_media_type)\n\nOr `undefined` when there is no match.\n\n#### input\n\nType: `ArrayBuffer | Uint8Array`\n\nIt only needs the first `minimumBytes` amount of bytes.\n\n### minimumBytes\n\nType: `number`\n\nThe minimum amount of bytes needed to detect a file type. Currently, it's 4100 bytes, but it can change, so don't hardcode it.\n\n## Supported file types\n\n- [`jpg`](https://en.wikipedia.org/wiki/JPEG)\n- [`png`](https://en.wikipedia.org/wiki/Portable_Network_Graphics)\n- [`gif`](https://en.wikipedia.org/wiki/GIF)\n- [`webp`](https://en.wikipedia.org/wiki/WebP)\n- [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format)\n- [`cr2`](https://fileinfo.com/extension/cr2)\n- [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format)\n- [`bmp`](https://en.wikipedia.org/wiki/BMP_file_format)\n- [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR)\n- [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format)\n- [`ico`](https://en.wikipedia.org/wiki/ICO_(file_format))\n- [`bpg`](https://bellard.org/bpg/)\n- [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000\n- [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000\n- [`jpx`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000\n- [`heic`](https://nokiatech.github.io/heif/technical.html)\n- [`cur`](https://en.wikipedia.org/wiki/ICO_(file_format))\n- [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image File\n\n*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).*\n\n## Related\n\n- [file-type](https://github.com/sindresorhus/file-type) - Detect the type of a file\n- [image-dimensions](https://github.com/sindresorhus/image-dimensions) - Get the dimensions of an image\n","publish_time":1747738094769,"_cnpm_publish_time":1747738094769,"dist-tags":{"latest":"6.1.0"}}