{"id":13528353,"url":"https://github.com/image-size/image-size","last_synced_at":"2025-05-06T02:54:14.742Z","repository":{"id":38369278,"uuid":"11110541","full_name":"image-size/image-size","owner":"image-size","description":"Node module for detecting image dimensions","archived":false,"fork":false,"pushed_at":"2025-04-02T14:29:23.000Z","size":7708,"stargazers_count":2120,"open_issues_count":38,"forks_count":205,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-05-06T02:54:08.400Z","etag":null,"topics":["dimensions","image-analysis","image-size"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/image-size.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,"zenodo":null}},"created_at":"2013-07-01T23:58:32.000Z","updated_at":"2025-05-06T00:51:02.000Z","dependencies_parsed_at":"2023-02-14T17:15:26.823Z","dependency_job_id":"ce04bbee-1583-46d5-a6bf-b4c9f18ce5c3","html_url":"https://github.com/image-size/image-size","commit_stats":{"total_commits":484,"total_committers":42,"mean_commits":"11.523809523809524","dds":"0.47107438016528924","last_synced_commit":"a7a24a3fc4ce750cec253618d33967b3b9d331d7"},"previous_names":[],"tags_count":70,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/image-size%2Fimage-size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/image-size%2Fimage-size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/image-size%2Fimage-size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/image-size%2Fimage-size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/image-size","download_url":"https://codeload.github.com/image-size/image-size/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252612465,"owners_count":21776254,"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","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":["dimensions","image-analysis","image-size"],"created_at":"2024-08-01T06:02:27.630Z","updated_at":"2025-05-06T02:54:14.726Z","avatar_url":"https://github.com/image-size.png","language":"TypeScript","readme":"# image-size\n\n[![Build Status](https://circleci.com/gh/image-size/image-size.svg?style=shield)](https://circleci.com/gh/image-size/image-size)\n[![Package Version](https://img.shields.io/npm/v/image-size.svg)](https://www.npmjs.com/package/image-size)\n[![Downloads](https://img.shields.io/npm/dm/image-size.svg)](http://npm-stat.com/charts.html?package=image-size\u0026author=netroy\u0026from=\u0026to=)\n\nFast, lightweight NodeJS package to get dimensions of any image file or buffer.\n\n## Key Features\n- Zero dependencies\n- Supports all major image formats\n- Works with both files and buffers\n- Minimal memory footprint - reads only image headers\n- ESM and CommonJS support\n- TypeScript types included\n\n## Supported formats\n\n- BMP\n- CUR\n- DDS\n- GIF\n- HEIC (HEIF, AVCI, AVIF)\n- ICNS\n- ICO\n- J2C\n- JPEG-2000 (JP2)\n- JPEG\n- JPEG-XL\n- KTX (1 and 2)\n- PNG\n- PNM (PAM, PBM, PFM, PGM, PPM)\n- PSD\n- SVG\n- TGA\n- TIFF\n- WebP\n\n## Installation\n\n```shell\nnpm install image-size\n# or\nyarn add image-size\n# or\npnpm add image-size\n```\n\n## Usage\n\n### Passing in a Buffer/Uint8Array\nBest for streams, network requests, or when you already have the image data in memory.\n\n```javascript\nimport { imageSize } from 'image-size'\n// or\nconst { imageSize } = require('image-size')\n\nconst dimensions = imageSize(buffer)\nconsole.log(dimensions.width, dimensions.height)\n```\n\n### Reading from a file\nBest for local files. Returns a promise.\n\n```javascript\nimport { imageSizeFromFile } from 'image-size/fromFile'\n// or\nconst { imageSizeFromFile } = require('image-size/fromFile')\n\nconst dimensions = await imageSizeFromFile('photos/image.jpg')\nconsole.log(dimensions.width, dimensions.height)\n```\n\nNote: Reading from files has a default concurrency limit of **100**\nTo change this limit, you can call the `setConcurrency` function like this:\n\n```javascript\nimport { setConcurrency } from 'image-size/fromFile'\n// or\nconst { setConcurrency } = require('image-size/fromFile')\nsetConcurrency(123456)\n```\n\n### Reading from a file Syncronously (not recommended) ⚠️\nv1.x of this library had a sync API, that internally used sync file reads.  \n\nThis isn't recommended because this blocks the node.js main thread, which reduces the performance, and prevents this library from being used concurrently.  \n\nHowever if you still need to use this package syncronously, you can read the file syncronously into a buffer, and then pass the buffer to this library.  \n\n```javascript\nimport { readFileSync } from 'node:fs'\nimport { imageSize } from 'image-size'\n\nconst buffer = readFileSync('photos/image.jpg')\nconst dimensions = imageSize(buffer)\nconsole.log(dimensions.width, dimensions.height)\n```\n\n### 3. Command Line\nUseful for quick checks.\n\n```shell\nnpx image-size image1.jpg image2.png\n```\n\n### Multi-size\n\nIf the target file/buffer is an HEIF, an ICO, or a CUR file, the `width` and `height` will be the ones of the largest image in the set.\n\nAn additional `images` array is available and returns the dimensions of all the available images\n\n```javascript\nimport { imageSizeFromFile } from 'image-size/fromFile'\n// or\nconst { imageSizeFromFile } = require('image-size/fromFile')\n\nconst { images } = await imageSizeFromFile('images/multi-size.ico')\nfor (const dimensions of images) {\n  console.log(dimensions.width, dimensions.height)\n}\n```\n\n### Using a URL\n\n```javascript\nimport url from 'node:url'\nimport http from 'node:http'\nimport { imageSize } from 'image-size'\n\nconst imgUrl = 'http://my-amazing-website.com/image.jpeg'\nconst options = url.parse(imgUrl)\n\nhttp.get(options, function (response) {\n  const chunks = []\n  response\n    .on('data', function (chunk) {\n      chunks.push(chunk)\n    })\n    .on('end', function () {\n      const buffer = Buffer.concat(chunks)\n      console.log(imageSize(buffer))\n    })\n})\n```\n\n### Disabling certain image types\n\n```javascript\nimport { disableTypes } from 'image-size'\n// or\nconst { disableTypes } = require('image-size')\n\ndisableTypes(['tiff', 'ico'])\n```\n\n### JPEG image orientation\n\nIf the orientation is present in the JPEG EXIF metadata, it will be returned by the function. The orientation value is a [number between 1 and 8](https://exiftool.org/TagNames/EXIF.html#:~:text=0x0112,8%20=%20Rotate%20270%20CW) representing a type of orientation.\n\n```javascript\nimport { imageSizeFromFile } from 'image-size/fromFile'\n// or\nconst { imageSizeFromFile } = require('image-size/fromFile')\n\nconst { width, height, orientation } = await imageSizeFromFile('images/photo.jpeg')\nconsole.log(width, height, orientation)\n```\n\n# Limitations\n\n1. **Partial File Reading**\n   - Only reads image headers, not full files\n   - Some corrupted images might still report dimensions\n\n2. **SVG Limitations**\n   - Only supports pixel dimensions and viewBox\n   - Percentage values not supported\n\n3. **File Access**\n   - Reading from files has a default concurrency limit of 100\n   - Can be adjusted using `setConcurrency()`\n\n4. **Buffer Requirements**\n   - Some formats (like TIFF) require the full header in buffer\n   - Streaming partial buffers may not work for all formats\n\n## License\n\nMIT\n\n## Credits\n\nnot a direct port, but an attempt to have something like\n[dabble's imagesize](https://github.com/dabble/imagesize/blob/master/lib/image_size.rb) as a node module.\n\n## [Contributors](Contributors.md)\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimage-size%2Fimage-size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimage-size%2Fimage-size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimage-size%2Fimage-size/lists"}