{"id":13559741,"url":"https://github.com/sindresorhus/image-dimensions","last_synced_at":"2025-10-07T04:41:00.847Z","repository":{"id":205611858,"uuid":"714675984","full_name":"sindresorhus/image-dimensions","owner":"sindresorhus","description":"Get the dimensions of an image","archived":false,"fork":false,"pushed_at":"2025-09-08T12:20:59.000Z","size":2201,"stargazers_count":453,"open_issues_count":1,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-09-19T12:45:52.300Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2023-11-05T15:20:19.000Z","updated_at":"2025-09-17T08:54:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"6480a2d1-24e0-4929-b0a6-8b26d809cc8c","html_url":"https://github.com/sindresorhus/image-dimensions","commit_stats":{"total_commits":15,"total_committers":4,"mean_commits":3.75,"dds":"0.33333333333333337","last_synced_commit":"e550b6253e925eb190cf7ae02f13542f86b73ece"},"previous_names":["sindresorhus/image-dimensions"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/sindresorhus/image-dimensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fimage-dimensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fimage-dimensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fimage-dimensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fimage-dimensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/image-dimensions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fimage-dimensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278722728,"owners_count":26034461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:00:32.392Z","updated_at":"2025-10-07T04:41:00.841Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript","Packages","包"],"sub_categories":["Image","图像"],"readme":"# image-dimensions\n\n\u003e 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//=\u003e {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\u003cUint8Array\u003e): Promise\u003c{width: number; height: number; type: ImageType} | undefined\u003e`\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//=\u003e {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//=\u003e {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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fimage-dimensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fimage-dimensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fimage-dimensions/lists"}