{"name":"image-dimensions","version":"2.0.0","keywords":["image","dimensions","width","height","size","resolution","metadata","uint8array","buffer","data","bytes","binary","stream","cli","cli-app","png","jpeg","jpg"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"image-dimensions@2.0.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"},{"name":"jongleberry","email":"jonathanrichardong@gmail.com"}],"homepage":"https://github.com/sindresorhus/image-dimensions#readme","bugs":{"url":"https://github.com/sindresorhus/image-dimensions/issues"},"bin":{"image-dimensions":"cli.js"},"dist":{"shasum":"b6e5ec29d4b0cb7aad0a67ee226d18cc513f6f50","tarball":"http://registry-npm.ywwl.com/image-dimensions/download/image-dimensions-2.0.0.tgz","fileCount":8,"integrity":"sha512-pRD4EAC1htlKwfzHdegauTHaEXdY64ICKMrY3qxdRz8zZL0VI3vM5m96Dkx5XEXlFj41Ak6NZB7y2R2nkGzZKQ==","signatures":[{"sig":"MEUCIQDPVEcKLO3YpYsRierH9ps/Hd5DoqqnnYKzxfcU/yaeewIgcIDZUv7g+fx2nFOqNTi3sPgBa3LtAWQlDBCujbuk4Xw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8410,"size":3156,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-2.0.0.tgz"},"type":"module","types":"./index.d.ts","engines":{"node":">=18"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"15552b905cbb53ac9119fd7ea3474e96e65e8af4","scripts":{"test":"xo && ava && tsc index.d.ts"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/image-dimensions.git","type":"git"},"_npmVersion":"9.2.0","description":"Get the dimensions of a PNG or JPEG image","directories":{},"_nodeVersion":"20.9.0","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.56.0","ava":"^5.3.1","typescript":"^5.2.2"},"_npmOperationalInternal":{"tmp":"tmp/image-dimensions_2.0.0_1699197813886_0.6648453507918071","host":"s3://npm-registry-packages"},"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":1699197814057,"_cnpm_publish_time":1699197814057,"dist-tags":{"latest":"2.6.0"}}