{"name":"image-dimensions","version":"1.0.0","keywords":["image","dimensions","browser"],"author":{"url":"http://jongleberry.com","name":"Jonathan Ong","email":"me@jongleberry.com"},"license":"MIT","_id":"image-dimensions@1.0.0","maintainers":[{"name":"jongleberry","email":"jonathanrichardong@gmail.com"}],"homepage":"https://github.com/mgmtio/image-dimensions","bugs":{"url":"https://github.com/mgmtio/image-dimensions/issues"},"dist":{"shasum":"018046697458a08ab0372231e022fcedcbc0f095","tarball":"http://registry-npm.ywwl.com/image-dimensions/download/image-dimensions-1.0.0.tgz","integrity":"sha512-9s7E9wG5PAFCD8mUsaMZ/CYSk2aHUMGmZk/TbQZMDGb+bSBxKzhDrZxQrtXz7rvgvp5ptZex2JEy1Nkz3SBQJA==","signatures":[{"sig":"MEQCIGjwWEaV3g7WUWZnyHIse7VOMAmGc1AAPVGcXZiMOm/7AiAZXLTd7nyCrXcr9T81TmdMUSBQ3MEbQ5UUzGRm3WnhAA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":1990,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-1.0.0.tgz"},"_from":".","files":["index.js"],"_shasum":"018046697458a08ab0372231e022fcedcbc0f095","gitHead":"3d277ef1f5193799d03b341b50da8a94eafc80ba","scripts":{"lint":"standardberry index.js","test":"mocha","test-ci":"npm run lint && istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot","test-cov":"istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot"},"_npmUser":{"name":"jongleberry","email":"jonathanrichardong@gmail.com"},"repository":{"url":"https://github.com/mgmtio/image-dimensions","type":"git"},"_npmVersion":"2.7.5","description":"Get the dimensions of a file input","directories":{},"_nodeVersion":"1.6.4","devDependencies":{"mocha":"2","istanbul":"0","standardberry":"*"},"readme":"# image-dimensions\n\n> Get the dimensions of an image\n\n*Works in any modern JavaScript environment (browsers, Node.js, Bun, Deno, etc).*\n\nSupporting all kinds of image formats is a non-goal. However, pull requests for adding JPEG XL are welcome.\n\n## Supported formats\n\n- JPEG\n- PNG (and APNG)\n- GIF\n- WebP\n- AVIF\n- HEIF (including HEIC)\n\n## Install\n\n```sh\nnpm install image-dimensions\n```\n\n## Usage\n\n```js\nimport {imageDimensionsFromStream} from 'image-dimensions';\n\n// In this example, it will only read a few bytes of the image instead of fetching the whole thing.\n\nconst url = 'https://sindresorhus.com/unicorn';\n\nconst {body} = await fetch(url);\n\nconsole.log(await imageDimensionsFromStream(body));\n//=> {width: 1920, height: 1080, type: 'png'}\n```\n\n## API\n\n`ImageType` is exported and can be one of: `'png'`, `'jpeg'`, `'gif'`, `'webp'`, `'avif'`, or `'heic'`.\n\n### `imageDimensionsFromStream(stream: ReadableStream<Uint8Array>): Promise<{width: number; height: number; type: ImageType} | undefined>`\n\nGet the dimensions of an image by reading the least amount of data.\n\nPrefer this method.\n\nReturns the image dimensions and type, or `undefined` if the image format is not supported or the image data is invalid.\n\nNote: Returns raw pixel dimensions; orientation (EXIF or HEIF/AVIF `irot`) is not applied.\n\n```js\n// Node.js example\nimport {createReadStream} from 'node:fs';\nimport {Readable} from 'node:stream';\nimport {imageDimensionsFromStream} from 'image-dimensions';\n\nconst stream = Readable.toWeb(createReadStream('unicorn.png'));\n\nconsole.log(await imageDimensionsFromStream(stream));\n//=> {width: 1920, height: 1080, type: 'png'}\n```\n\n### `imageDimensionsFromData(data: Uint8Array): {width: number; height: number; type: ImageType} | undefined`\n\nGet the dimensions of an image from data.\n\nThis method can be useful if you already have the image loaded in memory.\n\nReturns the image dimensions and type, or `undefined` if the image format is not supported or the image data is invalid.\n\nNote: Returns raw pixel dimensions; orientation (EXIF or HEIF/AVIF `irot`) is not applied.\n\n```js\nimport {imageDimensionsFromData} from 'image-dimensions';\n\nconst data = getImage();\n\nconsole.log(imageDimensionsFromData(data));\n//=> {width: 1920, height: 1080, type: 'png'}\n```\n\n## CLI\n\n```sh\nnpx image-dimensions unicorn.png\n630x400\n```\n\n## FAQ\n\n### How does this differ from [`image-size`](https://github.com/image-size/image-size)?\n\n**Advantages of this package**\n\n- Zero dependencies\n- Smaller\n- Works in non-Node.js environments like the browser\n- Does not include unnecessary APIs for file reading\n\n**Advantages of `image-size`**\n\n- Supports more image formats\n- Supports getting JPEG image orientation\n\n## Related\n\n- [image-type](https://github.com/sindresorhus/image-type) - Detect the type of an image\n- [file-type](https://github.com/sindresorhus/file-type) - Detect the type of a file\n","publish_time":1428989776051,"_cnpm_publish_time":1428989776051,"dist-tags":{"latest":"2.6.0"}}