Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,7 @@ contributor-beginner/build/
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Keep vendored image-size build (security patch)
!website/vendor/image-size/dist/
!website/vendor/image-size/dist/**
17 changes: 5 additions & 12 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"dompurify": "3.4.13",
"fast-uri": "4.1.3",
"http-proxy-middleware": "2.0.10",
"image-size": "file:vendor/image-size",
"joi": "18.2.5",
"js-yaml": "4.3.2",
"launch-editor": "2.14.1",
Expand Down Expand Up @@ -101,6 +102,7 @@
"dompurify": "3.4.13",
"fast-uri": "4.1.3",
"http-proxy-middleware": "2.0.10",
"image-size": "file:vendor/image-size",
"joi": "18.2.5",
"js-yaml": "4.3.2",
"launch-editor": "2.14.1",
Expand Down
9 changes: 9 additions & 0 deletions website/vendor/image-size/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright © 2013-Present Aditya Yadav, http://netroy.in

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
198 changes: 198 additions & 0 deletions website/vendor/image-size/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# image-size

[![Build Status](https://circleci.com/gh/image-size/image-size.svg?style=shield)](https://circleci.com/gh/image-size/image-size)
[![Package Version](https://img.shields.io/npm/v/image-size.svg)](https://www.npmjs.com/package/image-size)
[![Downloads](https://img.shields.io/npm/dm/image-size.svg)](http://npm-stat.com/charts.html?package=image-size&author=netroy&from=&to=)

Fast, lightweight NodeJS package to get dimensions of any image file or buffer.

## Key Features
- Zero dependencies
- Supports all major image formats
- Works with both files and buffers
- Minimal memory footprint - reads only image headers
- ESM and CommonJS support
- TypeScript types included

## Supported formats

- BMP
- CUR
- DDS
- GIF
- HEIC (HEIF, AVCI, AVIF)
- ICNS
- ICO
- J2C
- JPEG-2000 (JP2)
- JPEG
- JPEG-XL
- KTX (1 and 2)
- PNG
- PNM (PAM, PBM, PFM, PGM, PPM)
- PSD
- SVG
- TGA
- TIFF
- WebP

## Installation

```shell
npm install image-size
# or
yarn add image-size
# or
pnpm add image-size
```

## Usage

### Passing in a Buffer/Uint8Array
Best for streams, network requests, or when you already have the image data in memory.

```javascript
import { imageSize } from 'image-size'
// or
const { imageSize } = require('image-size')

const dimensions = imageSize(buffer)
console.log(dimensions.width, dimensions.height)
```

### Reading from a file
Best for local files. Returns a promise.

```javascript
import { imageSizeFromFile } from 'image-size/fromFile'
// or
const { imageSizeFromFile } = require('image-size/fromFile')

const dimensions = await imageSizeFromFile('photos/image.jpg')
console.log(dimensions.width, dimensions.height)
```

Note: Reading from files has a default concurrency limit of **100**
To change this limit, you can call the `setConcurrency` function like this:

```javascript
import { setConcurrency } from 'image-size/fromFile'
// or
const { setConcurrency } = require('image-size/fromFile')
setConcurrency(123456)
```

### Reading from a file Syncronously (not recommended) ⚠️
v1.x of this library had a sync API, that internally used sync file reads.

This isn't recommended because this blocks the node.js main thread, which reduces the performance, and prevents this library from being used concurrently.

However 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.

```javascript
import { readFileSync } from 'node:fs'
import { imageSize } from 'image-size'

const buffer = readFileSync('photos/image.jpg')
const dimensions = imageSize(buffer)
console.log(dimensions.width, dimensions.height)
```

### 3. Command Line
Useful for quick checks.

```shell
npx image-size image1.jpg image2.png
```

### Multi-size

If 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.

An additional `images` array is available and returns the dimensions of all the available images

```javascript
import { imageSizeFromFile } from 'image-size/fromFile'
// or
const { imageSizeFromFile } = require('image-size/fromFile')

const { images } = await imageSizeFromFile('images/multi-size.ico')
for (const dimensions of images) {
console.log(dimensions.width, dimensions.height)
}
```

### Using a URL

```javascript
import url from 'node:url'
import http from 'node:http'
import { imageSize } from 'image-size'

const imgUrl = 'http://my-amazing-website.com/image.jpeg'
const options = url.parse(imgUrl)

http.get(options, function (response) {
const chunks = []
response
.on('data', function (chunk) {
chunks.push(chunk)
})
.on('end', function () {
const buffer = Buffer.concat(chunks)
console.log(imageSize(buffer))
})
})
```

### Disabling certain image types

```javascript
import { disableTypes } from 'image-size'
// or
const { disableTypes } = require('image-size')

disableTypes(['tiff', 'ico'])
```

### JPEG image orientation

If 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.

```javascript
import { imageSizeFromFile } from 'image-size/fromFile'
// or
const { imageSizeFromFile } = require('image-size/fromFile')

const { width, height, orientation } = await imageSizeFromFile('images/photo.jpeg')
console.log(width, height, orientation)
```

# Limitations

1. **Partial File Reading**
- Only reads image headers, not full files
- Some corrupted images might still report dimensions

2. **SVG Limitations**
- Only supports pixel dimensions and viewBox
- Percentage values not supported

3. **File Access**
- Reading from files has a default concurrency limit of 100
- Can be adjusted using `setConcurrency()`

4. **Buffer Requirements**
- Some formats (like TIFF) require the full header in buffer
- Streaming partial buffers may not work for all formats

## License

MIT

## Credits

not a direct port, but an attempt to have something like
[dabble's imagesize](https://github.com/dabble/imagesize/blob/master/lib/image_size.rb) as a node module.

## [Contributors](Contributors.md)
17 changes: 17 additions & 0 deletions website/vendor/image-size/SECURITY-PATCH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Vendored `image-size` (2.0.3 local)

Temporary security fork of [`image-size@2.0.2`](https://www.npmjs.com/package/image-size) used via npm `overrides` / Yarn `resolutions`.

## Why

Upstream advisories GHSA-5p2g-fcmc-qvqq and GHSA-w3rx-r6r6-pgpr affect `<=2.0.2` and currently have **no patched npm release**. They cause infinite-loop DoS on crafted JXL/HEIF/ICNS buffers (zero-sized boxes/entries).

## Local changes

- Package version set to `2.0.3` so audit databases treat it as outside the vulnerable range
- Reject zero-sized ISO BMFF boxes in `readBox`
- Throw on zero-sized `ispe` / `jxlp` boxes and ICNS entries so offsets always advance

## Remove when

Upstream publishes a release `>2.0.2` that fixes those advisories. Then delete this folder and drop the `image-size` override/resolution.
48 changes: 48 additions & 0 deletions website/vendor/image-size/bin/image-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env node
'use strict'

const fs = require('node:fs')
const path = require('node:path')
const { imageSizeFromFile } = require('../dist/fromFile.cjs')

const files = process.argv.slice(2)

if (!files.length) {
console.error('Usage: image-size image1 [image2] [image3] ...')
process.exit(-1)
}

const red = ['\x1B[31m', '\x1B[39m']
const grey = ['\x1B[90m', '\x1B[39m']
const green = ['\x1B[32m', '\x1B[39m']

function colorize(text, color) {
return color[0] + text + color[1]
}

files.forEach(async (image) => {
try {
if (fs.existsSync(path.resolve(image))) {
const greyX = colorize('x', grey)
const greyImage = colorize(image, grey)
const result = await imageSizeFromFile(image)
const sizes = result.images || [result]
sizes.forEach((size) => {
const type = size.type ?? result.type;
const greyType = type ? colorize(` (${type})`, grey) : ''
console.info(
colorize(size.width, green) +
greyX +
colorize(size.height, green) +
' - ' +
greyImage +
greyType,
)
})
} else {
console.error("file doesn't exist - ", image)
}
} catch (e) {
console.error(colorize(e.message, red), '-', image)
}
})
Loading