{"name":"image-dimensions","version":"2.4.0","keywords":["image","dimensions","width","height","size","resolution","metadata","uint8array","buffer","data","bytes","binary","stream","cli","cli-app","png","jpeg","jpg","gif","webp","avif","heic","heif"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"image-dimensions@2.4.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@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":"ac2fe99c39b4642bd11ddee40d35667556dd92fa","tarball":"http://registry-npm.ywwl.com/image-dimensions/download/image-dimensions-2.4.0.tgz","fileCount":13,"integrity":"sha512-0SscKWh1jtXJStcsQHRLrE4Sgxd1y+g3E/28hiY1JElNfYX54MLjilwlU1AsfCmr/EdQPET4fewtbzuYNutJsQ==","signatures":[{"sig":"MEUCIQCSOfMp7p0mUPpAUxq+BR6FPzVnd+IObamZZYtAvBQX0QIgfzLD4ecggFR8CfCno+lu4ygojJPnB+kAWqCVA9IG5g0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18012,"size":5731,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-2.4.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":"d4b588077b5470bab243e4264670e15ba4da9841","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":"10.9.2","description":"Get the dimensions of an image","directories":{},"sideEffects":false,"_nodeVersion":"20.19.1","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.56.0","ava":"^6.0.1","typescript":"^5.3.3"},"_npmOperationalInternal":{"tmp":"tmp/image-dimensions_2.4.0_1756042488560_0.6830110005975494","host":"s3://npm-registry-packages-npm-production"},"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":1756042488782,"_cnpm_publish_time":1756042488782,"dist-tags":{"latest":"2.6.0"}}