{"name":"image-type","version":"5.1.0","description":"Detect the image type of a Buffer/Uint8Array","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/image-type.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["image","picture","photo","type","detect","check","is","exif","binary","buffer","uint8array","png","jpg","jpeg","gif","webp","tif","bmp","jxr","psd","mime"],"dependencies":{"file-type":"^17.1.4"},"devDependencies":{"@types/node":"^18.6.2","ava":"^4.3.1","read-chunk":"^4.0.2","tsd":"^0.22.0","xo":"^0.51.0"},"gitHead":"a336b53a5c83e65937d9e4206daf394aff261154","bugs":{"url":"https://github.com/sindresorhus/image-type/issues"},"homepage":"https://github.com/sindresorhus/image-type#readme","_id":"image-type@5.1.0","_nodeVersion":"14.19.3","_npmVersion":"8.3.2","dist":{"integrity":"sha512-7oH2RB8IkwOVRfbaG63Xlm5tYPgUy8C0HfeIoE+MQ2zfAf2d5qjyyOEKT8JAR6rcWQQLZAHDdFwdCEWf7gNOmw==","shasum":"b5d780918d32c89fa2714ee0b5095cfa71dde16e","tarball":"http://registry-npm.ywwl.com/image-type/download/image-type-5.1.0.tgz","fileCount":5,"unpackedSize":6972,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDcrbTfZe1Z3v7LzmoyAXPdaPoZVYj4SaGRoBa7Oe84gwIhAPYfn8UQA0ZGfpTh8xGDSQiXxSf3iEI4c38qrTcK7rgZ"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjLzXBACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq6SA/+Mx8V69wdGetyTG/RRWmJHu7Z1dXAchOyx6/h+C9H09CNvWDT\r\nJ8qcwWP2PF24CSbdK3o7vySKxPIR1/5xWLRerHU/w9tRnedmQ3/DyJSujrY4\r\nnqdy520/EtQZUnjdxeVl59Ubfk+FTUzTGeUNMEWwm91xu1CPgKdc9qKNJBIx\r\njFHe7Lky7vJdra3Z0/IveK/0l2RbK8ABTiOp/7IKDyeeiT/EpgweZk3lxWPV\r\n6zOMvt6WFAmbAaGYS6B+20MMaY60bSw4n6smVgp1IhvQuptHAbKCcjtFkddg\r\n5gybDuIwIgnzSeZmpo8+eR8UnPMvuRUXXVKC1b5PcLs31Vqqd7S58tZH2jgC\r\n55D1t/gtZGP+4RldTWwyLHG4ryxjjxfYyLRAHH9HiEQNbOPl33sZ70nfMTh6\r\nsahtAKL+/X1xXBcTLteTDqlgYGwtoM5EjvagZopU68nDN4msu595J1HMnL4R\r\n6qoUEydQLouhzo92Zzg+ab+CYbCtYAxn6Ww5u0rguq+N0toNJIkJ0KRwKFkN\r\nthYDRYZRM0r7YRyVklkJWEnAyCFFIDQtiwXpJtQLPyibsHoUod5e44FLymq1\r\nPA5HEti16T9W78DchgNvJ/GiVnqG4Ft7dteV53QsuU5/DcAars4MsoRBiBcs\r\nE5MKsJbYhgkkWG+GyjHL9kMdcevW2bJB2NQ=\r\n=3dEz\r\n-----END PGP SIGNATURE-----\r\n","size":2852,"noattachment":false,"key":"/image-type/-/image-type-5.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/image-type_5.1.0_1664038337737_0.3271404193082008"},"_hasShrinkwrap":false,"readme":"# image-type\n\n> Detect the image type of a Buffer/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: `Buffer | 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","publish_time":1664038337895,"_cnpm_publish_time":1664038337895,"dist-tags":{"latest":"6.1.0"}}