{"_id":"@carboneio/image-size","name":"@carboneio/image-size","dist-tags":{"latest":"3.0.0"},"versions":{"3.0.0":{"name":"@carboneio/image-size","version":"3.0.0","description":"get dimensions of any image file","publishConfig":{"access":"public"},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.cjs"}},"./fromFile":{"import":{"types":"./dist/fromFile.d.ts","default":"./dist/fromFile.mjs"},"require":{"types":"./dist/fromFile.d.ts","default":"./dist/fromFile.cjs"}},"./types/*":{"import":{"types":"./dist/types/*.d.ts","default":"./dist/types/*.mjs"},"require":{"types":"./dist/types/*.d.ts","default":"./dist/types/*.cjs"}}},"engines":{"node":">=16.x"},"bin":{"image-size":"bin/image-size.js"},"scripts":{"lint":"biome check lib specs","format":"biome format --write lib specs","test":"TS_NODE_PROJECT=tsconfig.test.json c8 --reporter=text --reporter=lcov node --require ts-node/register --test --test-reporter=dot specs/*.spec.ts","test:watch":"TS_NODE_PROJECT=tsconfig.test.json node --require ts-node/register --test --watch specs/*.spec.ts","bench":"TS_NODE_PROJECT=tsconfig.test.json node --require ts-node/register specs/benchmark.ts","clean":"rm -rf dist docs","generate-docs":"typedoc","build":"tsup","prepack":"npm run clean && npm run build"},"keywords":["image","size","dimensions","resolution","width","height","avif","bmp","cur","gif","heic","heif","icns","ico","jpeg","jxl","png","psd","svg","tga","tiff","webp"],"repository":{"type":"git","url":"git+https://github.com/carboneio/image-size.git"},"homepage":"https://github.com/carboneio/image-size#readme","bugs":{"url":"https://github.com/carboneio/image-size/issues"},"author":{"name":"netroy","email":"aditya@netroy.in","url":"http://netroy.in/"},"license":"MIT","devDependencies":{"@biomejs/biome":"1.9.4","@types/glob":"8.1.0","@types/node":"18.19.39","c8":"10.1.3","glob":"13.0.6","ts-node":"10.9.2","tsup":"8.3.5","typedoc":"0.25.13","typescript":"5.4.5"},"c8":{"include":["lib/**/*.ts"],"check-coverage":true,"statements":100,"branches":100,"functions":100,"lines":100},"gitHead":"0e9af586def3a2c065e827b07283bb2dca2dfad5","_id":"@carboneio/image-size@3.0.0","_nodeVersion":"24.18.1","_npmVersion":"11.16.0","dist":{"integrity":"sha512-v5VUNsoRnTKsUSCYfGvcMuv2xEK/Qs1hoPsXKjf5KNBEmqiyYrcUR5lwU/7cA+cq9byEmFfNKR5Z7M35UIcysg==","shasum":"ab2f4e72b257980550c0bb88259d3ef35175fdad","tarball":"https://registry.npmjs.org/@carboneio/image-size/-/image-size-3.0.0.tgz","fileCount":117,"unpackedSize":448694,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDbgiXV0sJZ7jSXNsaLQuJIHpMvpteMBdf4GRC9X+h47QIhAMer9pBaFRZ0xRuzIgvXkbtffoTSIubH4X3qtKob2iko"}]},"_npmUser":{"name":"dgrelaud","email":"dgrelaud@ideolys.com"},"directories":{},"maintainers":[{"name":"steevepay","email":"steeve@carbone.io"},{"name":"guillaume-carbone","email":"guillaume@carbone.io"},{"name":"dgrelaud","email":"dgrelaud@ideolys.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/image-size_3.0.0_1788858257362_0.9373222826534318"},"_hasShrinkwrap":false}},"time":{"created":"2026-09-08T09:04:17.210Z","3.0.0":"2026-09-08T09:04:17.480Z","modified":"2026-09-08T09:04:17.800Z"},"maintainers":[{"name":"steevepay","email":"steeve@carbone.io"},{"name":"guillaume-carbone","email":"guillaume@carbone.io"},{"name":"dgrelaud","email":"dgrelaud@ideolys.com"}],"description":"get dimensions of any image file","homepage":"https://github.com/carboneio/image-size#readme","keywords":["image","size","dimensions","resolution","width","height","avif","bmp","cur","gif","heic","heif","icns","ico","jpeg","jxl","png","psd","svg","tga","tiff","webp"],"repository":{"type":"git","url":"git+https://github.com/carboneio/image-size.git"},"author":{"name":"netroy","email":"aditya@netroy.in","url":"http://netroy.in/"},"bugs":{"url":"https://github.com/carboneio/image-size/issues"},"license":"MIT","readme":"# @carboneio/image-size\n\nFast, lightweight NodeJS package to get dimensions of any image file or buffer.\n\n## Forked by [Carbone](https://carbone.io)\n\n[![Build and test](https://github.com/carboneio/image-size/actions/workflows/build-test.yml/badge.svg?branch=main)](https://github.com/carboneio/image-size/actions/workflows/build-test.yml)\n[![NPM Version](https://img.shields.io/npm/v/@carboneio/image-size.svg?style=flat-square)](https://www.npmjs.com/package/@carboneio/image-size)\n[![Downloads](https://img.shields.io/npm/dm/@carboneio/image-size.svg?style=flat-square)](https://www.npmjs.com/package/@carboneio/image-size)\n[![Code style: Biome](https://img.shields.io/badge/code_style-biome-60a5fa.svg?style=flat-square)](https://biomejs.dev/)\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg?style=flat-square)](https://github.com/carboneio/image-size)\n\nAfter a thorough security audit (pentest) of our dependencies, we decided to fork this project ([image-size on GitHub](https://github.com/image-size/image-size) and [image-size on Codeberg](https://codeberg.org/image-size/image-size)) to fix several vulnerabilities and, in the process, optimize the library. For a detailed list of changes, please see the [full changelog](CHANGELOG.md).\n\nWe started by ensuring the test suite had 100% code coverage before making any changes. We also compared our results and [Performance section](#performance) with the tests from [sharp](https://github.com/lovell/sharp), a widely used, more general-purpose library.  \n\nWe would like to warmly thank the original developer of this library for their excellent work. We are maintaining this fork only because we needed to apply some urgent fixes and improvements; as soon as the original project incorporates these corrections, we will be very happy to remove this fork and return to the main repository.\n\nPlease note that we will maintain this project as long as it remains relevant to our needs, but cannot guarantee support for issues outside our own roadmap.\n\n\n## Key Features\n\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- Tested via GitHub Actions CI on Node.js 18, 20, 22, 24, and 26\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 @carboneio/image-size\n# or\nyarn add @carboneio/image-size\n# or\npnpm add @carboneio/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 '@carboneio/image-size'\n// or\nconst { imageSize } = require('@carboneio/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 '@carboneio/image-size/fromFile'\n// or\nconst { imageSizeFromFile } = require('@carboneio/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 '@carboneio/image-size/fromFile'\n// or\nconst { setConcurrency } = require('@carboneio/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 '@carboneio/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 @carboneio/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 '@carboneio/image-size/fromFile'\n// or\nconst { imageSizeFromFile } = require('@carboneio/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 '@carboneio/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 '@carboneio/image-size'\n// or\nconst { disableTypes } = require('@carboneio/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 '@carboneio/image-size/fromFile'\n// or\nconst { imageSizeFromFile } = require('@carboneio/image-size/fromFile')\n\nconst { width, height, orientation } = await imageSizeFromFile('images/photo.jpeg')\nconsole.log(width, height, orientation)\n```\n\n# Performance\n\n`image-size` reads a header; [sharp](https://github.com/lovell/sharp) decodes\nan image. That makes them hard to compare on anything but this one question:\n*how long does it take to learn an image's dimensions?* They give the same\nanswer: across sharp's own 501 test fixtures, the two libraries agree on all\n496 that both can read.\n\nMeasured against sharp 0.35.4 / libvips 8.18.6 on Node 24, macOS arm64.\n\n**From a buffer already in memory**,  parsing cost on its own:\n\n| Format | Fixture              |   sharp | image-size | Factor |\n| ------ | -------------------- | ------: | ---------: | -----: |\n| JPEG   | 810 kB, 2725x2225    |  101 µs |    0.48 µs |   209x |\n| PNG    | 6.8 MB, 2725x2225    |   76 µs |    0.34 µs |   226x |\n| WebP   | 173 kB, 1024x772     |  206 µs |    0.52 µs |   400x |\n| GIF    | 279 kB, 800x533      |   85 µs |    0.20 µs |   429x |\n| TIFF   | 249 kB, 246x345      |  122 µs |    0.63 µs |   195x |\n| AVIF   | 279 kB, 2048x858     |  102 µs |    1.39 µs |    74x |\n| SVG    | 32 kB, 480x360       |  263 µs |    2.10 µs |   125x |\n\n**From a file path**, what an application actually pays, I/O included:\n\n| Format | Size    |   sharp | image-size | Factor |\n| ------ | ------- | ------: | ---------: | -----: |\n| JPEG   | 810 kB  |  230 µs |     102 µs |   2.3x |\n| PNG    | 6.8 MB  |  124 µs |      99 µs |   1.3x |\n| WebP   | 173 kB  |  294 µs |      64 µs |   4.6x |\n| GIF    | 279 kB  |  191 µs |      73 µs |   2.6x |\n| TIFF   | 249 kB  |  285 µs |      69 µs |   4.1x |\n| AVIF   | 279 kB  |  342 µs |      75 µs |   4.6x |\n| SVG    | 32 kB   |  444 µs |      48 µs |   9.2x |\n\nThe second table is the one to plan with. Reading the file dominates the cost,\nso the two orders of magnitude on a buffer shrink to between 1.3x and 9.2x\nonce I/O is counted. `image-size` also has no native binary to install and no\nstart-up cost, where sharp pays about 50 ms on its first call.\n\nlibvips' cache is disabled for these numbers, since the benchmark re-reads the\nsame fixture in a loop and would otherwise measure memoisation rather than\nwork. Files are warm in the OS page cache on both sides. Run `npm run bench`\nfor throughput across all thirty formats.\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## Development\n\n```bash\nnpm ci          # install dependencies from package-lock.json\nnpm test        # unit tests, with a 100% coverage threshold\nnpm run bench   # detection throughput, per format, on small and large files\n```\n\n`npm run bench` accepts `--filter=<substring>` to benchmark a single format,\ne.g. `npm run bench -- --filter=webp`.\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","readmeFilename":"Readme.md","_rev":"1-048668d649a68d5268b601c7d7da4bfb"}