{"name":"image-type","version":"4.0.0","description":"Detect the image type of a Buffer/Uint8Array","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/image-type.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd-check"},"keywords":["image","img","pic","picture","photo","type","detect","check","is","exif","binary","buffer","uint8array","png","jpg","jpeg","gif","webp","tif","bmp","jxr","psd","mime"],"dependencies":{"file-type":"^10.9.0"},"devDependencies":{"@types/node":"^11.10.4","ava":"^1.3.1","read-chunk":"^3.0.0","tsd-check":"^0.3.0","xo":"^0.24.0"},"gitHead":"333daed89e27a7ca967ff88221ce959ca4e78cd6","bugs":{"url":"https://github.com/sindresorhus/image-type/issues"},"homepage":"https://github.com/sindresorhus/image-type#readme","_id":"image-type@4.0.0","_nodeVersion":"8.15.0","_npmVersion":"6.8.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-V1NCIexmmA9dBoO07NOFXe2nTU06siLuuaGD1zLRbLfTYmGMLPShPakPf3ts6J0ctdpLpJRKFcJWKjuacwZzWA==","shasum":"91e84c887451644706ff3297360ff3d89881fac5","tarball":"http://registry-npm.ywwl.com/image-type/download/image-type-4.0.0.tgz","fileCount":5,"unpackedSize":6416,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcf2tkCRA9TVsSAnZWagAAD+wP/jnfpJ1xLjnEN7YL3gYn\n6p47FI6Tct8MwNP3RhucVwTvAKGKLKKfSujLsMa/DH1jgB3n1cX7B6MzGQXP\nqFs/zcuolS5WQpulYPIxxQvaWLpetogE5vYUUFboMEcl8mdSLzYiT0epdcgI\nTmI55Jr3e9IQXw6OWG9414V0BrfM9k11kxBoslk5NDM0E6geKCqNtjxxPuZD\n6K2mCGMF/huCvaerA8o6LDDNDoXFdqrQ0IMDf+DvED5XzmOt9k0G/tOrx9iX\nhkM3nSzcubBgLdQDjK3yMf/bbZQJCM5oMIZtAEdWawDxaIeZR+ap/QSesyqj\nV6flvWUHhLnv1MSc2JS90/OcDcIpPQ5tvEQ5l2KLOvu7e0N2C43ls0VNNjl9\ngJBxogHUfhjWzrS/UJKkD5QxjEU103opRUU3mwko+pPoHls63reNow2FsPq3\n9RoSaJK7SMPTHRGsekxMHNCy4tOF7EqLGWFkFW0wAF2aqi7yB7ye+PfLbVi5\n5Vl1mlZhiq2vLM0RlSXJzmSQziS6+z0zid6qHGdCknlHmhrZtw8t/g/nZRMg\nszPhW1dh2zpU5OU2DpAjxvzl0OB0yS48rZSwrf/nZQB76ZEI2BTAI2y9uoqM\nZ2QwxIu+B6Qi10YVF+MMFOjIQM93B6tGhUvNJQ3fpBoll9YdKfYz4qVygKfc\nEdKT\r\n=W/Z7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB9RyyJufefhzhTIm5Yn3LlFZVjZj9yndpJjZWvaQ54uAiBrusxWdmq+8zey+pkZW9gXsqGSisN6v92L08Ej6fdKvA=="}],"size":2867,"noattachment":false,"key":"/image-type/-/image-type-4.0.0.tgz"},"maintainers":[{"name":"kevva","email":"kevinmartensson@gmail.com"},{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/image-type_4.0.0_1551854436326_0.016372582616225984"},"_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":1551854436472,"_cnpm_publish_time":1551854436472,"dist-tags":{"latest":"6.1.0"}}