{"_id":"image-dimensions","_rev":"4109099","name":"image-dimensions","description":"Get the dimensions of an image","dist-tags":{"latest":"2.5.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-01-23T00:52:20.000Z","created":"2015-04-14T05:36:16.051Z","2.5.0":"2025-09-08T12:20:57.237Z","2.4.0":"2025-08-24T13:34:48.782Z","2.3.0":"2023-12-19T22:11:04.182Z","2.2.0":"2023-11-08T11:18:47.410Z","2.1.0":"2023-11-06T10:06:38.737Z","2.0.0":"2023-11-05T15:23:34.057Z","1.0.0":"2015-04-14T05:36:16.051Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/image-dimensions.git"},"versions":{"2.5.0":{"name":"image-dimensions","version":"2.5.0","description":"Get the dimensions of an image","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/image-dimensions.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","bin":{"image-dimensions":"cli.js"},"exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsc index.d.ts"},"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"],"devDependencies":{"ava":"^6.0.1","typescript":"^5.3.3","xo":"^0.56.0"},"_id":"image-dimensions@2.5.0","gitHead":"aa978c8d17d96a1c73e571689b40cf046fba0a72","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/image-dimensions/issues"},"homepage":"https://github.com/sindresorhus/image-dimensions#readme","_nodeVersion":"22.12.0","_npmVersion":"10.9.2","dist":{"shasum":"57476c343228fb73beccdfd2686d2633f35f382b","size":5917,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-2.5.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/image-dimensions/download/image-dimensions-2.5.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/image-dimensions_2.5.0_1757334057039_0.32821833583672144"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-09-08T12:20:57.237Z","publish_time":1757334057237,"_source_registry_name":"default","_cnpm_publish_time":1757334057237},"2.4.0":{"name":"image-dimensions","version":"2.4.0","description":"Get the dimensions of an image","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/image-dimensions.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","bin":{"image-dimensions":"cli.js"},"exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsc index.d.ts"},"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"],"devDependencies":{"ava":"^6.0.1","typescript":"^5.3.3","xo":"^0.56.0"},"_id":"image-dimensions@2.4.0","gitHead":"d4b588077b5470bab243e4264670e15ba4da9841","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/image-dimensions/issues"},"homepage":"https://github.com/sindresorhus/image-dimensions#readme","_nodeVersion":"20.19.1","_npmVersion":"10.9.2","dist":{"shasum":"ac2fe99c39b4642bd11ddee40d35667556dd92fa","size":5731,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-2.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/image-dimensions/download/image-dimensions-2.4.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/image-dimensions_2.4.0_1756042488560_0.6830110005975494"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-08-24T13:34:48.782Z","publish_time":1756042488782,"_source_registry_name":"default","_cnpm_publish_time":1756042488782},"2.3.0":{"name":"image-dimensions","version":"2.3.0","description":"Get the dimensions of an image","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/image-dimensions.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","bin":{"image-dimensions":"cli.js"},"exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsc index.d.ts"},"keywords":["image","dimensions","width","height","size","resolution","metadata","uint8array","buffer","data","bytes","binary","stream","cli","cli-app","png","jpeg","jpg","gif","webp","avif"],"devDependencies":{"ava":"^6.0.1","typescript":"^5.3.3","xo":"^0.56.0"},"types":"./index.d.ts","gitHead":"5a103f90178f23fb2271c65bf3a3682db016692d","bugs":{"url":"https://github.com/sindresorhus/image-dimensions/issues"},"homepage":"https://github.com/sindresorhus/image-dimensions#readme","_id":"image-dimensions@2.3.0","_nodeVersion":"18.19.0","_npmVersion":"9.2.0","dist":{"shasum":"ddb549de9e0825a4df2568bafae9a6dd306354d4","size":4820,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-2.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/image-dimensions/download/image-dimensions-2.3.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/image-dimensions_2.3.0_1703023863954_0.9079503769571724"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-12-19T22:11:04.182Z","publish_time":1703023864182,"_source_registry_name":"default","_cnpm_publish_time":1703023864182},"2.2.0":{"name":"image-dimensions","version":"2.2.0","description":"Get the dimensions of an image","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/image-dimensions.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","bin":{"image-dimensions":"cli.js"},"exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsc index.d.ts"},"keywords":["image","dimensions","width","height","size","resolution","metadata","uint8array","buffer","data","bytes","binary","stream","cli","cli-app","png","jpeg","jpg","gif","webp","avif"],"devDependencies":{"ava":"^5.3.1","typescript":"^5.2.2","xo":"^0.56.0"},"types":"./index.d.ts","gitHead":"aacf19d1a35bfd54bdd7764e2c7e1d3cf7b122b3","bugs":{"url":"https://github.com/sindresorhus/image-dimensions/issues"},"homepage":"https://github.com/sindresorhus/image-dimensions#readme","_id":"image-dimensions@2.2.0","_nodeVersion":"20.9.0","_npmVersion":"9.2.0","dist":{"shasum":"cce252e1861d2723497a436f4f15ee183436b165","size":4482,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-2.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/image-dimensions/download/image-dimensions-2.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/image-dimensions_2.2.0_1699442327225_0.36626720010410874"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-08T11:18:47.410Z","publish_time":1699442327410,"_source_registry_name":"default","_cnpm_publish_time":1699442327410},"2.1.0":{"name":"image-dimensions","version":"2.1.0","description":"Get the dimensions of an image","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/image-dimensions.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","bin":{"image-dimensions":"cli.js"},"exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsc index.d.ts"},"keywords":["image","dimensions","width","height","size","resolution","metadata","uint8array","buffer","data","bytes","binary","stream","cli","cli-app","png","jpeg","jpg","gif"],"devDependencies":{"ava":"^5.3.1","typescript":"^5.2.2","xo":"^0.56.0"},"types":"./index.d.ts","gitHead":"971fd1aa8b09815d2b58fe6b98d8bb6ec5977e87","bugs":{"url":"https://github.com/sindresorhus/image-dimensions/issues"},"homepage":"https://github.com/sindresorhus/image-dimensions#readme","_id":"image-dimensions@2.1.0","_nodeVersion":"20.9.0","_npmVersion":"9.2.0","dist":{"shasum":"5bc780490a8fb0d16fc80daa4f58c2710e0cbb2f","size":3345,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/image-dimensions/download/image-dimensions-2.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/image-dimensions_2.1.0_1699265198543_0.22074715134281608"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-06T10:06:38.737Z","publish_time":1699265198737,"_source_registry_name":"default","_cnpm_publish_time":1699265198737},"2.0.0":{"name":"image-dimensions","version":"2.0.0","description":"Get the dimensions of a PNG or JPEG image","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/image-dimensions.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","bin":{"image-dimensions":"cli.js"},"exports":{"types":"./index.d.ts","default":"./index.js"},"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsc index.d.ts"},"keywords":["image","dimensions","width","height","size","resolution","metadata","uint8array","buffer","data","bytes","binary","stream","cli","cli-app","png","jpeg","jpg"],"devDependencies":{"ava":"^5.3.1","typescript":"^5.2.2","xo":"^0.56.0"},"types":"./index.d.ts","gitHead":"15552b905cbb53ac9119fd7ea3474e96e65e8af4","bugs":{"url":"https://github.com/sindresorhus/image-dimensions/issues"},"homepage":"https://github.com/sindresorhus/image-dimensions#readme","_id":"image-dimensions@2.0.0","_nodeVersion":"20.9.0","_npmVersion":"9.2.0","dist":{"shasum":"b6e5ec29d4b0cb7aad0a67ee226d18cc513f6f50","size":3156,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/image-dimensions/download/image-dimensions-2.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/image-dimensions_2.0.0_1699197813886_0.6648453507918071"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-05T15:23:34.057Z","publish_time":1699197814057,"_source_registry_name":"default","_cnpm_publish_time":1699197814057},"1.0.0":{"name":"image-dimensions","description":"Get the dimensions of a file input","version":"1.0.0","author":{"name":"Jonathan Ong","email":"me@jongleberry.com","url":"http://jongleberry.com"},"license":"MIT","repository":{"type":"git","url":"https://github.com/mgmtio/image-dimensions"},"devDependencies":{"istanbul":"0","mocha":"2","standardberry":"*"},"scripts":{"lint":"standardberry index.js","test":"mocha","test-cov":"istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot","test-ci":"npm run lint && istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"},"keywords":["image","dimensions","browser"],"files":["index.js"],"gitHead":"3d277ef1f5193799d03b341b50da8a94eafc80ba","bugs":{"url":"https://github.com/mgmtio/image-dimensions/issues"},"homepage":"https://github.com/mgmtio/image-dimensions","_id":"image-dimensions@1.0.0","_shasum":"018046697458a08ab0372231e022fcedcbc0f095","_from":".","_npmVersion":"2.7.5","_nodeVersion":"1.6.4","_npmUser":{"name":"jongleberry","email":"jonathanrichardong@gmail.com"},"maintainers":[{"name":"sindresorhus","email":""}],"dist":{"shasum":"018046697458a08ab0372231e022fcedcbc0f095","size":1990,"noattachment":false,"key":"/image-dimensions/-/image-dimensions-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/image-dimensions/download/image-dimensions-1.0.0.tgz"},"directories":{},"_cnpmcore_publish_time":"2021-12-23T12:19:24.413Z","publish_time":1428989776051,"_cnpm_publish_time":1428989776051}},"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 {imageDimensionsFromStream} from 'image-dimensions';\n\nconst stream = ReadableStream.from(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","_attachments":{},"homepage":"https://github.com/sindresorhus/image-dimensions#readme","bugs":{"url":"https://github.com/sindresorhus/image-dimensions/issues"},"license":"MIT"}