first
This commit is contained in:
9
node_modules/image-size/LICENSE
generated
vendored
Normal file
9
node_modules/image-size/LICENSE
generated
vendored
Normal file
@ -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.
|
||||
184
node_modules/image-size/Readme.md
generated
vendored
Normal file
184
node_modules/image-size/Readme.md
generated
vendored
Normal file
@ -0,0 +1,184 @@
|
||||
# image-size
|
||||
|
||||
[](https://circleci.com/gh/image-size/image-size)
|
||||
[](https://www.npmjs.com/package/image-size)
|
||||
[](http://npm-stat.com/charts.html?package=image-size&author=&from=&to=)
|
||||
|
||||
A [Node](https://nodejs.org/en/) module to get dimensions of any image file
|
||||
|
||||
## 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
|
||||
|
||||
## Programmatic Usage
|
||||
|
||||
```shell
|
||||
npm install image-size --save
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```shell
|
||||
yarn add image-size
|
||||
```
|
||||
|
||||
### Synchronous
|
||||
|
||||
```javascript
|
||||
const sizeOf = require("image-size")
|
||||
const dimensions = sizeOf("images/funny-cats.png")
|
||||
console.log(dimensions.width, dimensions.height)
|
||||
```
|
||||
|
||||
### Asynchronous
|
||||
|
||||
```javascript
|
||||
const sizeOf = require("image-size")
|
||||
sizeOf("images/funny-cats.png", function (err, dimensions) {
|
||||
console.log(dimensions.width, dimensions.height)
|
||||
})
|
||||
```
|
||||
|
||||
NOTE: The asynchronous version doesn't work if the input is a Buffer. Use synchronous version instead.
|
||||
|
||||
Also, the asynchronous functions have a default concurrency limit of **100**
|
||||
To change this limit, you can call the `setConcurrency` function like this:
|
||||
|
||||
```javascript
|
||||
const sizeOf = require("image-size")
|
||||
sizeOf.setConcurrency(123456)
|
||||
```
|
||||
|
||||
### Using promises (nodejs 10.x+)
|
||||
|
||||
```javascript
|
||||
const { promisify } = require("util")
|
||||
const sizeOf = promisify(require("image-size"))
|
||||
sizeOf("images/funny-cats.png")
|
||||
.then((dimensions) => {
|
||||
console.log(dimensions.width, dimensions.height)
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
```
|
||||
|
||||
### Async/Await (Typescript & ES7)
|
||||
|
||||
```javascript
|
||||
const { promisify } = require("util")
|
||||
const sizeOf = promisify(require("image-size"))(async () => {
|
||||
try {
|
||||
const dimensions = await sizeOf("images/funny-cats.png")
|
||||
console.log(dimensions.width, dimensions.height)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
})().then((c) => console.log(c))
|
||||
```
|
||||
|
||||
### Multi-size
|
||||
|
||||
If the target file is an icon (.ico) or a cursor (.cur), the `width` and `height` will be the ones of the first found image.
|
||||
|
||||
An additional `images` array is available and returns the dimensions of all the available images
|
||||
|
||||
```javascript
|
||||
const sizeOf = require("image-size")
|
||||
const images = sizeOf("images/multi-size.ico").images
|
||||
for (const dimensions of images) {
|
||||
console.log(dimensions.width, dimensions.height)
|
||||
}
|
||||
```
|
||||
|
||||
### Using a URL
|
||||
|
||||
```javascript
|
||||
const url = require("url")
|
||||
const http = require("http")
|
||||
|
||||
const sizeOf = require("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(sizeOf(buffer))
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
You can optionally check the buffer lengths & stop downloading the image after a few kilobytes.
|
||||
**You don't need to download the entire image**
|
||||
|
||||
### Disabling certain image types
|
||||
|
||||
```javascript
|
||||
const imageSize = require("image-size")
|
||||
imageSize.disableTypes(["tiff", "ico"])
|
||||
```
|
||||
|
||||
### Disabling all file-system reads
|
||||
|
||||
```javascript
|
||||
const imageSize = require("image-size")
|
||||
imageSize.disableFS(true)
|
||||
```
|
||||
|
||||
### 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
|
||||
const sizeOf = require("image-size")
|
||||
const dimensions = sizeOf("images/photo.jpeg")
|
||||
console.log(dimensions.orientation)
|
||||
```
|
||||
|
||||
## Command-Line Usage (CLI)
|
||||
|
||||
```shell
|
||||
npm install image-size --global
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```shell
|
||||
yarn global add image-size
|
||||
```
|
||||
|
||||
followed by
|
||||
|
||||
```shell
|
||||
image-size image1 [image2] [image3] ...
|
||||
```
|
||||
|
||||
## 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)
|
||||
53
node_modules/image-size/bin/image-size.js
generated
vendored
Executable file
53
node_modules/image-size/bin/image-size.js
generated
vendored
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { imageSize } = require('..')
|
||||
|
||||
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 bold = ['\x1B[1m', '\x1B[22m']
|
||||
const grey = ['\x1B[90m', '\x1B[39m']
|
||||
const green = ['\x1B[32m', '\x1B[39m']
|
||||
|
||||
function colorize(text, color) {
|
||||
return color[0] + text + color[1]
|
||||
}
|
||||
|
||||
files.forEach(function (image) {
|
||||
try {
|
||||
if (fs.existsSync(path.resolve(image))) {
|
||||
const greyX = colorize('x', grey)
|
||||
const greyImage = colorize(image, grey)
|
||||
const size = imageSize(image)
|
||||
const sizes = size.images || [size]
|
||||
sizes.forEach((size) => {
|
||||
let greyType = ''
|
||||
if (size.type) {
|
||||
greyType = colorize(' (' + size.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(e.stack)
|
||||
console.error(colorize(e.message, red), '-', image)
|
||||
}
|
||||
})
|
||||
2
node_modules/image-size/dist/detector.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/detector.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { imageType } from './types/index';
|
||||
export declare function detector(input: Uint8Array): imageType | undefined;
|
||||
30
node_modules/image-size/dist/detector.js
generated
vendored
Normal file
30
node_modules/image-size/dist/detector.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.detector = void 0;
|
||||
const index_1 = require("./types/index");
|
||||
const keys = Object.keys(index_1.typeHandlers);
|
||||
// This map helps avoid validating for every single image type
|
||||
const firstBytes = {
|
||||
0x38: 'psd',
|
||||
0x42: 'bmp',
|
||||
0x44: 'dds',
|
||||
0x47: 'gif',
|
||||
0x49: 'tiff',
|
||||
0x4d: 'tiff',
|
||||
0x52: 'webp',
|
||||
0x69: 'icns',
|
||||
0x89: 'png',
|
||||
0xff: 'jpg',
|
||||
};
|
||||
function detector(input) {
|
||||
const byte = input[0];
|
||||
if (byte in firstBytes) {
|
||||
const type = firstBytes[byte];
|
||||
if (type && index_1.typeHandlers[type].validate(input)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
const finder = (key) => index_1.typeHandlers[key].validate(input);
|
||||
return keys.find(finder);
|
||||
}
|
||||
exports.detector = detector;
|
||||
10
node_modules/image-size/dist/index.d.ts
generated
vendored
Normal file
10
node_modules/image-size/dist/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import type { imageType } from './types/index';
|
||||
import type { ISizeCalculationResult } from './types/interface';
|
||||
type CallbackFn = (e: Error | null, r?: ISizeCalculationResult) => void;
|
||||
export default imageSize;
|
||||
export declare function imageSize(input: Uint8Array | string): ISizeCalculationResult;
|
||||
export declare function imageSize(input: string, callback: CallbackFn): void;
|
||||
export declare const disableFS: (v: boolean) => void;
|
||||
export declare const disableTypes: (types: imageType[]) => void;
|
||||
export declare const setConcurrency: (c: number) => void;
|
||||
export declare const types: string[];
|
||||
129
node_modules/image-size/dist/index.js
generated
vendored
Normal file
129
node_modules/image-size/dist/index.js
generated
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.types = exports.setConcurrency = exports.disableTypes = exports.disableFS = exports.imageSize = void 0;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const queue_1 = require("queue");
|
||||
const index_1 = require("./types/index");
|
||||
const detector_1 = require("./detector");
|
||||
// Maximum input size, with a default of 512 kilobytes.
|
||||
// TO-DO: make this adaptive based on the initial signature of the image
|
||||
const MaxInputSize = 512 * 1024;
|
||||
// This queue is for async `fs` operations, to avoid reaching file-descriptor limits
|
||||
const queue = new queue_1.default({ concurrency: 100, autostart: true });
|
||||
const globalOptions = {
|
||||
disabledFS: false,
|
||||
disabledTypes: [],
|
||||
};
|
||||
/**
|
||||
* Return size information based on an Uint8Array
|
||||
*
|
||||
* @param {Uint8Array} input
|
||||
* @param {String} filepath
|
||||
* @returns {Object}
|
||||
*/
|
||||
function lookup(input, filepath) {
|
||||
// detect the file type.. don't rely on the extension
|
||||
const type = (0, detector_1.detector)(input);
|
||||
if (typeof type !== 'undefined') {
|
||||
if (globalOptions.disabledTypes.indexOf(type) > -1) {
|
||||
throw new TypeError('disabled file type: ' + type);
|
||||
}
|
||||
// find an appropriate handler for this file type
|
||||
if (type in index_1.typeHandlers) {
|
||||
const size = index_1.typeHandlers[type].calculate(input, filepath);
|
||||
if (size !== undefined) {
|
||||
size.type = size.type ?? type;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
// throw up, if we don't understand the file
|
||||
throw new TypeError('unsupported file type: ' + type + ' (file: ' + filepath + ')');
|
||||
}
|
||||
/**
|
||||
* Reads a file into an Uint8Array.
|
||||
* @param {String} filepath
|
||||
* @returns {Promise<Uint8Array>}
|
||||
*/
|
||||
async function readFileAsync(filepath) {
|
||||
const handle = await fs.promises.open(filepath, 'r');
|
||||
try {
|
||||
const { size } = await handle.stat();
|
||||
if (size <= 0) {
|
||||
throw new Error('Empty file');
|
||||
}
|
||||
const inputSize = Math.min(size, MaxInputSize);
|
||||
const input = new Uint8Array(inputSize);
|
||||
await handle.read(input, 0, inputSize, 0);
|
||||
return input;
|
||||
}
|
||||
finally {
|
||||
await handle.close();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Synchronously reads a file into an Uint8Array, blocking the nodejs process.
|
||||
*
|
||||
* @param {String} filepath
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
function readFileSync(filepath) {
|
||||
// read from the file, synchronously
|
||||
const descriptor = fs.openSync(filepath, 'r');
|
||||
try {
|
||||
const { size } = fs.fstatSync(descriptor);
|
||||
if (size <= 0) {
|
||||
throw new Error('Empty file');
|
||||
}
|
||||
const inputSize = Math.min(size, MaxInputSize);
|
||||
const input = new Uint8Array(inputSize);
|
||||
fs.readSync(descriptor, input, 0, inputSize, 0);
|
||||
return input;
|
||||
}
|
||||
finally {
|
||||
fs.closeSync(descriptor);
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
module.exports = exports = imageSize; // backwards compatibility
|
||||
exports.default = imageSize;
|
||||
/**
|
||||
* @param {Uint8Array|string} input - Uint8Array or relative/absolute path of the image file
|
||||
* @param {Function=} [callback] - optional function for async detection
|
||||
*/
|
||||
function imageSize(input, callback) {
|
||||
// Handle Uint8Array input
|
||||
if (input instanceof Uint8Array) {
|
||||
return lookup(input);
|
||||
}
|
||||
// input should be a string at this point
|
||||
if (typeof input !== 'string' || globalOptions.disabledFS) {
|
||||
throw new TypeError('invalid invocation. input should be a Uint8Array');
|
||||
}
|
||||
// resolve the file path
|
||||
const filepath = path.resolve(input);
|
||||
if (typeof callback === 'function') {
|
||||
queue.push(() => readFileAsync(filepath)
|
||||
.then((input) => process.nextTick(callback, null, lookup(input, filepath)))
|
||||
.catch(callback));
|
||||
}
|
||||
else {
|
||||
const input = readFileSync(filepath);
|
||||
return lookup(input, filepath);
|
||||
}
|
||||
}
|
||||
exports.imageSize = imageSize;
|
||||
const disableFS = (v) => {
|
||||
globalOptions.disabledFS = v;
|
||||
};
|
||||
exports.disableFS = disableFS;
|
||||
const disableTypes = (types) => {
|
||||
globalOptions.disabledTypes = types;
|
||||
};
|
||||
exports.disableTypes = disableTypes;
|
||||
const setConcurrency = (c) => {
|
||||
queue.concurrency = c;
|
||||
};
|
||||
exports.setConcurrency = setConcurrency;
|
||||
exports.types = Object.keys(index_1.typeHandlers);
|
||||
2
node_modules/image-size/dist/types/bmp.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/bmp.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const BMP: IImage;
|
||||
11
node_modules/image-size/dist/types/bmp.js
generated
vendored
Normal file
11
node_modules/image-size/dist/types/bmp.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BMP = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
exports.BMP = {
|
||||
validate: (input) => (0, utils_1.toUTF8String)(input, 0, 2) === 'BM',
|
||||
calculate: (input) => ({
|
||||
height: Math.abs((0, utils_1.readInt32LE)(input, 22)),
|
||||
width: (0, utils_1.readUInt32LE)(input, 18),
|
||||
}),
|
||||
};
|
||||
2
node_modules/image-size/dist/types/cur.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/cur.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const CUR: IImage;
|
||||
17
node_modules/image-size/dist/types/cur.js
generated
vendored
Normal file
17
node_modules/image-size/dist/types/cur.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CUR = void 0;
|
||||
const ico_1 = require("./ico");
|
||||
const utils_1 = require("./utils");
|
||||
const TYPE_CURSOR = 2;
|
||||
exports.CUR = {
|
||||
validate(input) {
|
||||
const reserved = (0, utils_1.readUInt16LE)(input, 0);
|
||||
const imageCount = (0, utils_1.readUInt16LE)(input, 4);
|
||||
if (reserved !== 0 || imageCount === 0)
|
||||
return false;
|
||||
const imageType = (0, utils_1.readUInt16LE)(input, 2);
|
||||
return imageType === TYPE_CURSOR;
|
||||
},
|
||||
calculate: (input) => ico_1.ICO.calculate(input),
|
||||
};
|
||||
2
node_modules/image-size/dist/types/dds.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/dds.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const DDS: IImage;
|
||||
11
node_modules/image-size/dist/types/dds.js
generated
vendored
Normal file
11
node_modules/image-size/dist/types/dds.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DDS = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
exports.DDS = {
|
||||
validate: (input) => (0, utils_1.readUInt32LE)(input, 0) === 0x20534444,
|
||||
calculate: (input) => ({
|
||||
height: (0, utils_1.readUInt32LE)(input, 12),
|
||||
width: (0, utils_1.readUInt32LE)(input, 16),
|
||||
}),
|
||||
};
|
||||
2
node_modules/image-size/dist/types/gif.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/gif.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const GIF: IImage;
|
||||
12
node_modules/image-size/dist/types/gif.js
generated
vendored
Normal file
12
node_modules/image-size/dist/types/gif.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GIF = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
const gifRegexp = /^GIF8[79]a/;
|
||||
exports.GIF = {
|
||||
validate: (input) => gifRegexp.test((0, utils_1.toUTF8String)(input, 0, 6)),
|
||||
calculate: (input) => ({
|
||||
height: (0, utils_1.readUInt16LE)(input, 8),
|
||||
width: (0, utils_1.readUInt16LE)(input, 6),
|
||||
}),
|
||||
};
|
||||
2
node_modules/image-size/dist/types/heif.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/heif.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const HEIF: IImage;
|
||||
40
node_modules/image-size/dist/types/heif.js
generated
vendored
Normal file
40
node_modules/image-size/dist/types/heif.js
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HEIF = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
const brandMap = {
|
||||
avif: 'avif',
|
||||
mif1: 'heif',
|
||||
msf1: 'heif', // heif-sequence
|
||||
heic: 'heic',
|
||||
heix: 'heic',
|
||||
hevc: 'heic', // heic-sequence
|
||||
hevx: 'heic', // heic-sequence
|
||||
};
|
||||
exports.HEIF = {
|
||||
validate(input) {
|
||||
const boxType = (0, utils_1.toUTF8String)(input, 4, 8);
|
||||
if (boxType !== 'ftyp')
|
||||
return false;
|
||||
const ftypBox = (0, utils_1.findBox)(input, 'ftyp', 0);
|
||||
if (!ftypBox)
|
||||
return false;
|
||||
const brand = (0, utils_1.toUTF8String)(input, ftypBox.offset + 8, ftypBox.offset + 12);
|
||||
return brand in brandMap;
|
||||
},
|
||||
calculate(input) {
|
||||
// Based on https://nokiatech.github.io/heif/technical.html
|
||||
const metaBox = (0, utils_1.findBox)(input, 'meta', 0);
|
||||
const iprpBox = metaBox && (0, utils_1.findBox)(input, 'iprp', metaBox.offset + 12);
|
||||
const ipcoBox = iprpBox && (0, utils_1.findBox)(input, 'ipco', iprpBox.offset + 8);
|
||||
const ispeBox = ipcoBox && (0, utils_1.findBox)(input, 'ispe', ipcoBox.offset + 8);
|
||||
if (ispeBox) {
|
||||
return {
|
||||
height: (0, utils_1.readUInt32BE)(input, ispeBox.offset + 16),
|
||||
width: (0, utils_1.readUInt32BE)(input, ispeBox.offset + 12),
|
||||
type: (0, utils_1.toUTF8String)(input, 8, 12),
|
||||
};
|
||||
}
|
||||
throw new TypeError('Invalid HEIF, no size found');
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/icns.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/icns.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const ICNS: IImage;
|
||||
101
node_modules/image-size/dist/types/icns.js
generated
vendored
Normal file
101
node_modules/image-size/dist/types/icns.js
generated
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ICNS = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
/**
|
||||
* ICNS Header
|
||||
*
|
||||
* | Offset | Size | Purpose |
|
||||
* | 0 | 4 | Magic literal, must be "icns" (0x69, 0x63, 0x6e, 0x73) |
|
||||
* | 4 | 4 | Length of file, in bytes, msb first. |
|
||||
*
|
||||
*/
|
||||
const SIZE_HEADER = 4 + 4; // 8
|
||||
const FILE_LENGTH_OFFSET = 4; // MSB => BIG ENDIAN
|
||||
/**
|
||||
* Image Entry
|
||||
*
|
||||
* | Offset | Size | Purpose |
|
||||
* | 0 | 4 | Icon type, see OSType below. |
|
||||
* | 4 | 4 | Length of data, in bytes (including type and length), msb first. |
|
||||
* | 8 | n | Icon data |
|
||||
*/
|
||||
const ENTRY_LENGTH_OFFSET = 4; // MSB => BIG ENDIAN
|
||||
const ICON_TYPE_SIZE = {
|
||||
ICON: 32,
|
||||
'ICN#': 32,
|
||||
// m => 16 x 16
|
||||
'icm#': 16,
|
||||
icm4: 16,
|
||||
icm8: 16,
|
||||
// s => 16 x 16
|
||||
'ics#': 16,
|
||||
ics4: 16,
|
||||
ics8: 16,
|
||||
is32: 16,
|
||||
s8mk: 16,
|
||||
icp4: 16,
|
||||
// l => 32 x 32
|
||||
icl4: 32,
|
||||
icl8: 32,
|
||||
il32: 32,
|
||||
l8mk: 32,
|
||||
icp5: 32,
|
||||
ic11: 32,
|
||||
// h => 48 x 48
|
||||
ich4: 48,
|
||||
ich8: 48,
|
||||
ih32: 48,
|
||||
h8mk: 48,
|
||||
// . => 64 x 64
|
||||
icp6: 64,
|
||||
ic12: 32,
|
||||
// t => 128 x 128
|
||||
it32: 128,
|
||||
t8mk: 128,
|
||||
ic07: 128,
|
||||
// . => 256 x 256
|
||||
ic08: 256,
|
||||
ic13: 256,
|
||||
// . => 512 x 512
|
||||
ic09: 512,
|
||||
ic14: 512,
|
||||
// . => 1024 x 1024
|
||||
ic10: 1024,
|
||||
};
|
||||
function readImageHeader(input, imageOffset) {
|
||||
const imageLengthOffset = imageOffset + ENTRY_LENGTH_OFFSET;
|
||||
return [
|
||||
(0, utils_1.toUTF8String)(input, imageOffset, imageLengthOffset),
|
||||
(0, utils_1.readUInt32BE)(input, imageLengthOffset),
|
||||
];
|
||||
}
|
||||
function getImageSize(type) {
|
||||
const size = ICON_TYPE_SIZE[type];
|
||||
return { width: size, height: size, type };
|
||||
}
|
||||
exports.ICNS = {
|
||||
validate: (input) => (0, utils_1.toUTF8String)(input, 0, 4) === 'icns',
|
||||
calculate(input) {
|
||||
const inputLength = input.length;
|
||||
const fileLength = (0, utils_1.readUInt32BE)(input, FILE_LENGTH_OFFSET);
|
||||
let imageOffset = SIZE_HEADER;
|
||||
let imageHeader = readImageHeader(input, imageOffset);
|
||||
let imageSize = getImageSize(imageHeader[0]);
|
||||
imageOffset += imageHeader[1];
|
||||
if (imageOffset === fileLength)
|
||||
return imageSize;
|
||||
const result = {
|
||||
height: imageSize.height,
|
||||
images: [imageSize],
|
||||
width: imageSize.width,
|
||||
};
|
||||
while (imageOffset < fileLength && imageOffset < inputLength) {
|
||||
imageHeader = readImageHeader(input, imageOffset);
|
||||
imageSize = getImageSize(imageHeader[0]);
|
||||
imageOffset += imageHeader[1];
|
||||
result.images.push(imageSize);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/ico.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/ico.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const ICO: IImage;
|
||||
68
node_modules/image-size/dist/types/ico.js
generated
vendored
Normal file
68
node_modules/image-size/dist/types/ico.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ICO = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
const TYPE_ICON = 1;
|
||||
/**
|
||||
* ICON Header
|
||||
*
|
||||
* | Offset | Size | Purpose |
|
||||
* | 0 | 2 | Reserved. Must always be 0. |
|
||||
* | 2 | 2 | Image type: 1 for icon (.ICO) image, 2 for cursor (.CUR) image. Other values are invalid. |
|
||||
* | 4 | 2 | Number of images in the file. |
|
||||
*
|
||||
*/
|
||||
const SIZE_HEADER = 2 + 2 + 2; // 6
|
||||
/**
|
||||
* Image Entry
|
||||
*
|
||||
* | Offset | Size | Purpose |
|
||||
* | 0 | 1 | Image width in pixels. Can be any number between 0 and 255. Value 0 means width is 256 pixels. |
|
||||
* | 1 | 1 | Image height in pixels. Can be any number between 0 and 255. Value 0 means height is 256 pixels. |
|
||||
* | 2 | 1 | Number of colors in the color palette. Should be 0 if the image does not use a color palette. |
|
||||
* | 3 | 1 | Reserved. Should be 0. |
|
||||
* | 4 | 2 | ICO format: Color planes. Should be 0 or 1. |
|
||||
* | | | CUR format: The horizontal coordinates of the hotspot in number of pixels from the left. |
|
||||
* | 6 | 2 | ICO format: Bits per pixel. |
|
||||
* | | | CUR format: The vertical coordinates of the hotspot in number of pixels from the top. |
|
||||
* | 8 | 4 | The size of the image's data in bytes |
|
||||
* | 12 | 4 | The offset of BMP or PNG data from the beginning of the ICO/CUR file |
|
||||
*
|
||||
*/
|
||||
const SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4; // 16
|
||||
function getSizeFromOffset(input, offset) {
|
||||
const value = input[offset];
|
||||
return value === 0 ? 256 : value;
|
||||
}
|
||||
function getImageSize(input, imageIndex) {
|
||||
const offset = SIZE_HEADER + imageIndex * SIZE_IMAGE_ENTRY;
|
||||
return {
|
||||
height: getSizeFromOffset(input, offset + 1),
|
||||
width: getSizeFromOffset(input, offset),
|
||||
};
|
||||
}
|
||||
exports.ICO = {
|
||||
validate(input) {
|
||||
const reserved = (0, utils_1.readUInt16LE)(input, 0);
|
||||
const imageCount = (0, utils_1.readUInt16LE)(input, 4);
|
||||
if (reserved !== 0 || imageCount === 0)
|
||||
return false;
|
||||
const imageType = (0, utils_1.readUInt16LE)(input, 2);
|
||||
return imageType === TYPE_ICON;
|
||||
},
|
||||
calculate(input) {
|
||||
const nbImages = (0, utils_1.readUInt16LE)(input, 4);
|
||||
const imageSize = getImageSize(input, 0);
|
||||
if (nbImages === 1)
|
||||
return imageSize;
|
||||
const imgs = [imageSize];
|
||||
for (let imageIndex = 1; imageIndex < nbImages; imageIndex += 1) {
|
||||
imgs.push(getImageSize(input, imageIndex));
|
||||
}
|
||||
return {
|
||||
height: imageSize.height,
|
||||
images: imgs,
|
||||
width: imageSize.width,
|
||||
};
|
||||
},
|
||||
};
|
||||
23
node_modules/image-size/dist/types/index.d.ts
generated
vendored
Normal file
23
node_modules/image-size/dist/types/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
export declare const typeHandlers: {
|
||||
bmp: import("./interface").IImage;
|
||||
cur: import("./interface").IImage;
|
||||
dds: import("./interface").IImage;
|
||||
gif: import("./interface").IImage;
|
||||
heif: import("./interface").IImage;
|
||||
icns: import("./interface").IImage;
|
||||
ico: import("./interface").IImage;
|
||||
j2c: import("./interface").IImage;
|
||||
jp2: import("./interface").IImage;
|
||||
jpg: import("./interface").IImage;
|
||||
jxl: import("./interface").IImage;
|
||||
'jxl-stream': import("./interface").IImage;
|
||||
ktx: import("./interface").IImage;
|
||||
png: import("./interface").IImage;
|
||||
pnm: import("./interface").IImage;
|
||||
psd: import("./interface").IImage;
|
||||
svg: import("./interface").IImage;
|
||||
tga: import("./interface").IImage;
|
||||
tiff: import("./interface").IImage;
|
||||
webp: import("./interface").IImage;
|
||||
};
|
||||
export type imageType = keyof typeof typeHandlers;
|
||||
46
node_modules/image-size/dist/types/index.js
generated
vendored
Normal file
46
node_modules/image-size/dist/types/index.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.typeHandlers = void 0;
|
||||
// load all available handlers explicitly for browserify support
|
||||
const bmp_1 = require("./bmp");
|
||||
const cur_1 = require("./cur");
|
||||
const dds_1 = require("./dds");
|
||||
const gif_1 = require("./gif");
|
||||
const heif_1 = require("./heif");
|
||||
const icns_1 = require("./icns");
|
||||
const ico_1 = require("./ico");
|
||||
const j2c_1 = require("./j2c");
|
||||
const jp2_1 = require("./jp2");
|
||||
const jpg_1 = require("./jpg");
|
||||
const jxl_1 = require("./jxl");
|
||||
const jxl_stream_1 = require("./jxl-stream");
|
||||
const ktx_1 = require("./ktx");
|
||||
const png_1 = require("./png");
|
||||
const pnm_1 = require("./pnm");
|
||||
const psd_1 = require("./psd");
|
||||
const svg_1 = require("./svg");
|
||||
const tga_1 = require("./tga");
|
||||
const tiff_1 = require("./tiff");
|
||||
const webp_1 = require("./webp");
|
||||
exports.typeHandlers = {
|
||||
bmp: bmp_1.BMP,
|
||||
cur: cur_1.CUR,
|
||||
dds: dds_1.DDS,
|
||||
gif: gif_1.GIF,
|
||||
heif: heif_1.HEIF,
|
||||
icns: icns_1.ICNS,
|
||||
ico: ico_1.ICO,
|
||||
j2c: j2c_1.J2C,
|
||||
jp2: jp2_1.JP2,
|
||||
jpg: jpg_1.JPG,
|
||||
jxl: jxl_1.JXL,
|
||||
'jxl-stream': jxl_stream_1.JXLStream,
|
||||
ktx: ktx_1.KTX,
|
||||
png: png_1.PNG,
|
||||
pnm: pnm_1.PNM,
|
||||
psd: psd_1.PSD,
|
||||
svg: svg_1.SVG,
|
||||
tga: tga_1.TGA,
|
||||
tiff: tiff_1.TIFF,
|
||||
webp: webp_1.WEBP,
|
||||
};
|
||||
13
node_modules/image-size/dist/types/interface.d.ts
generated
vendored
Normal file
13
node_modules/image-size/dist/types/interface.d.ts
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
export interface ISize {
|
||||
width: number | undefined;
|
||||
height: number | undefined;
|
||||
orientation?: number;
|
||||
type?: string;
|
||||
}
|
||||
export type ISizeCalculationResult = {
|
||||
images?: ISize[];
|
||||
} & ISize;
|
||||
export interface IImage {
|
||||
validate: (input: Uint8Array) => boolean;
|
||||
calculate: (input: Uint8Array, filepath?: string) => ISizeCalculationResult;
|
||||
}
|
||||
2
node_modules/image-size/dist/types/interface.js
generated
vendored
Normal file
2
node_modules/image-size/dist/types/interface.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
node_modules/image-size/dist/types/j2c.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/j2c.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const J2C: IImage;
|
||||
12
node_modules/image-size/dist/types/j2c.js
generated
vendored
Normal file
12
node_modules/image-size/dist/types/j2c.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.J2C = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
exports.J2C = {
|
||||
// TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC
|
||||
validate: (input) => (0, utils_1.readUInt32BE)(input, 0) === 0xff4fff51,
|
||||
calculate: (input) => ({
|
||||
height: (0, utils_1.readUInt32BE)(input, 12),
|
||||
width: (0, utils_1.readUInt32BE)(input, 8),
|
||||
}),
|
||||
};
|
||||
2
node_modules/image-size/dist/types/jp2.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/jp2.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const JP2: IImage;
|
||||
27
node_modules/image-size/dist/types/jp2.js
generated
vendored
Normal file
27
node_modules/image-size/dist/types/jp2.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JP2 = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
exports.JP2 = {
|
||||
validate(input) {
|
||||
const boxType = (0, utils_1.toUTF8String)(input, 4, 8);
|
||||
if (boxType !== 'jP ')
|
||||
return false;
|
||||
const ftypBox = (0, utils_1.findBox)(input, 'ftyp', 0);
|
||||
if (!ftypBox)
|
||||
return false;
|
||||
const brand = (0, utils_1.toUTF8String)(input, ftypBox.offset + 8, ftypBox.offset + 12);
|
||||
return brand === 'jp2 ';
|
||||
},
|
||||
calculate(input) {
|
||||
const jp2hBox = (0, utils_1.findBox)(input, 'jp2h', 0);
|
||||
const ihdrBox = jp2hBox && (0, utils_1.findBox)(input, 'ihdr', jp2hBox.offset + 8);
|
||||
if (ihdrBox) {
|
||||
return {
|
||||
height: (0, utils_1.readUInt32BE)(input, ihdrBox.offset + 8),
|
||||
width: (0, utils_1.readUInt32BE)(input, ihdrBox.offset + 12),
|
||||
};
|
||||
}
|
||||
throw new TypeError('Unsupported JPEG 2000 format');
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/jpg.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/jpg.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const JPG: IImage;
|
||||
123
node_modules/image-size/dist/types/jpg.js
generated
vendored
Normal file
123
node_modules/image-size/dist/types/jpg.js
generated
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
"use strict";
|
||||
// NOTE: we only support baseline and progressive JPGs here
|
||||
// due to the structure of the loader class, we only get a buffer
|
||||
// with a maximum size of 4096 bytes. so if the SOF marker is outside
|
||||
// if this range we can't detect the file size correctly.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JPG = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
const EXIF_MARKER = '45786966';
|
||||
const APP1_DATA_SIZE_BYTES = 2;
|
||||
const EXIF_HEADER_BYTES = 6;
|
||||
const TIFF_BYTE_ALIGN_BYTES = 2;
|
||||
const BIG_ENDIAN_BYTE_ALIGN = '4d4d';
|
||||
const LITTLE_ENDIAN_BYTE_ALIGN = '4949';
|
||||
// Each entry is exactly 12 bytes
|
||||
const IDF_ENTRY_BYTES = 12;
|
||||
const NUM_DIRECTORY_ENTRIES_BYTES = 2;
|
||||
function isEXIF(input) {
|
||||
return (0, utils_1.toHexString)(input, 2, 6) === EXIF_MARKER;
|
||||
}
|
||||
function extractSize(input, index) {
|
||||
return {
|
||||
height: (0, utils_1.readUInt16BE)(input, index),
|
||||
width: (0, utils_1.readUInt16BE)(input, index + 2),
|
||||
};
|
||||
}
|
||||
function extractOrientation(exifBlock, isBigEndian) {
|
||||
// TODO: assert that this contains 0x002A
|
||||
// let STATIC_MOTOROLA_TIFF_HEADER_BYTES = 2
|
||||
// let TIFF_IMAGE_FILE_DIRECTORY_BYTES = 4
|
||||
// TODO: derive from TIFF_IMAGE_FILE_DIRECTORY_BYTES
|
||||
const idfOffset = 8;
|
||||
// IDF osset works from right after the header bytes
|
||||
// (so the offset includes the tiff byte align)
|
||||
const offset = EXIF_HEADER_BYTES + idfOffset;
|
||||
const idfDirectoryEntries = (0, utils_1.readUInt)(exifBlock, 16, offset, isBigEndian);
|
||||
for (let directoryEntryNumber = 0; directoryEntryNumber < idfDirectoryEntries; directoryEntryNumber++) {
|
||||
const start = offset +
|
||||
NUM_DIRECTORY_ENTRIES_BYTES +
|
||||
directoryEntryNumber * IDF_ENTRY_BYTES;
|
||||
const end = start + IDF_ENTRY_BYTES;
|
||||
// Skip on corrupt EXIF blocks
|
||||
if (start > exifBlock.length) {
|
||||
return;
|
||||
}
|
||||
const block = exifBlock.slice(start, end);
|
||||
const tagNumber = (0, utils_1.readUInt)(block, 16, 0, isBigEndian);
|
||||
// 0x0112 (decimal: 274) is the `orientation` tag ID
|
||||
if (tagNumber === 274) {
|
||||
const dataFormat = (0, utils_1.readUInt)(block, 16, 2, isBigEndian);
|
||||
if (dataFormat !== 3) {
|
||||
return;
|
||||
}
|
||||
// unsinged int has 2 bytes per component
|
||||
// if there would more than 4 bytes in total it's a pointer
|
||||
const numberOfComponents = (0, utils_1.readUInt)(block, 32, 4, isBigEndian);
|
||||
if (numberOfComponents !== 1) {
|
||||
return;
|
||||
}
|
||||
return (0, utils_1.readUInt)(block, 16, 8, isBigEndian);
|
||||
}
|
||||
}
|
||||
}
|
||||
function validateExifBlock(input, index) {
|
||||
// Skip APP1 Data Size
|
||||
const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index);
|
||||
// Consider byte alignment
|
||||
const byteAlign = (0, utils_1.toHexString)(exifBlock, EXIF_HEADER_BYTES, EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES);
|
||||
// Ignore Empty EXIF. Validate byte alignment
|
||||
const isBigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN;
|
||||
const isLittleEndian = byteAlign === LITTLE_ENDIAN_BYTE_ALIGN;
|
||||
if (isBigEndian || isLittleEndian) {
|
||||
return extractOrientation(exifBlock, isBigEndian);
|
||||
}
|
||||
}
|
||||
function validateInput(input, index) {
|
||||
// index should be within buffer limits
|
||||
if (index > input.length) {
|
||||
throw new TypeError('Corrupt JPG, exceeded buffer limits');
|
||||
}
|
||||
}
|
||||
exports.JPG = {
|
||||
validate: (input) => (0, utils_1.toHexString)(input, 0, 2) === 'ffd8',
|
||||
calculate(input) {
|
||||
// Skip 4 chars, they are for signature
|
||||
input = input.slice(4);
|
||||
let orientation;
|
||||
let next;
|
||||
while (input.length) {
|
||||
// read length of the next block
|
||||
const i = (0, utils_1.readUInt16BE)(input, 0);
|
||||
// Every JPEG block must begin with a 0xFF
|
||||
if (input[i] !== 0xff) {
|
||||
input = input.slice(1);
|
||||
continue;
|
||||
}
|
||||
if (isEXIF(input)) {
|
||||
orientation = validateExifBlock(input, i);
|
||||
}
|
||||
// ensure correct format
|
||||
validateInput(input, i);
|
||||
// 0xFFC0 is baseline standard(SOF)
|
||||
// 0xFFC1 is baseline optimized(SOF)
|
||||
// 0xFFC2 is progressive(SOF2)
|
||||
next = input[i + 1];
|
||||
if (next === 0xc0 || next === 0xc1 || next === 0xc2) {
|
||||
const size = extractSize(input, i + 5);
|
||||
// TODO: is orientation=0 a valid answer here?
|
||||
if (!orientation) {
|
||||
return size;
|
||||
}
|
||||
return {
|
||||
height: size.height,
|
||||
orientation,
|
||||
width: size.width,
|
||||
};
|
||||
}
|
||||
// move to the next block
|
||||
input = input.slice(i + 2);
|
||||
}
|
||||
throw new TypeError('Invalid JPG, no size found');
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/jxl-stream.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/jxl-stream.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const JXLStream: IImage;
|
||||
45
node_modules/image-size/dist/types/jxl-stream.js
generated
vendored
Normal file
45
node_modules/image-size/dist/types/jxl-stream.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JXLStream = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
const bit_reader_1 = require("../utils/bit-reader");
|
||||
function calculateImageDimension(reader, isSmallImage) {
|
||||
if (isSmallImage) {
|
||||
// Small images are multiples of 8 pixels, up to 256 pixels
|
||||
return 8 * (1 + reader.getBits(5));
|
||||
}
|
||||
else {
|
||||
// Larger images use a variable bit-length encoding
|
||||
const sizeClass = reader.getBits(2);
|
||||
const extraBits = [9, 13, 18, 30][sizeClass];
|
||||
return 1 + reader.getBits(extraBits);
|
||||
}
|
||||
}
|
||||
function calculateImageWidth(reader, isSmallImage, widthMode, height) {
|
||||
if (isSmallImage && widthMode === 0) {
|
||||
// Small square images
|
||||
return 8 * (1 + reader.getBits(5));
|
||||
}
|
||||
else if (widthMode === 0) {
|
||||
// Non-small images with explicitly coded width
|
||||
return calculateImageDimension(reader, false);
|
||||
}
|
||||
else {
|
||||
// Images with width derived from height and aspect ratio
|
||||
const aspectRatios = [1, 1.2, 4 / 3, 1.5, 16 / 9, 5 / 4, 2];
|
||||
return Math.floor(height * aspectRatios[widthMode - 1]);
|
||||
}
|
||||
}
|
||||
exports.JXLStream = {
|
||||
validate: (input) => {
|
||||
return (0, utils_1.toHexString)(input, 0, 2) === 'ff0a';
|
||||
},
|
||||
calculate(input) {
|
||||
const reader = new bit_reader_1.BitReader(input, 'little-endian');
|
||||
const isSmallImage = reader.getBits(1) === 1;
|
||||
const height = calculateImageDimension(reader, isSmallImage);
|
||||
const widthMode = reader.getBits(3);
|
||||
const width = calculateImageWidth(reader, isSmallImage, widthMode, height);
|
||||
return { width, height };
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/jxl.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/jxl.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const JXL: IImage;
|
||||
59
node_modules/image-size/dist/types/jxl.js
generated
vendored
Normal file
59
node_modules/image-size/dist/types/jxl.js
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JXL = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
const jxl_stream_1 = require("./jxl-stream");
|
||||
/** Extracts the codestream from a containerized JPEG XL image */
|
||||
function extractCodestream(input) {
|
||||
const jxlcBox = (0, utils_1.findBox)(input, 'jxlc', 0);
|
||||
if (jxlcBox) {
|
||||
return input.slice(jxlcBox.offset + 8, jxlcBox.offset + jxlcBox.size);
|
||||
}
|
||||
const partialStreams = extractPartialStreams(input);
|
||||
if (partialStreams.length > 0) {
|
||||
return concatenateCodestreams(partialStreams);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/** Extracts partial codestreams from jxlp boxes */
|
||||
function extractPartialStreams(input) {
|
||||
const partialStreams = [];
|
||||
let offset = 0;
|
||||
while (offset < input.length) {
|
||||
const jxlpBox = (0, utils_1.findBox)(input, 'jxlp', offset);
|
||||
if (!jxlpBox)
|
||||
break;
|
||||
partialStreams.push(input.slice(jxlpBox.offset + 12, jxlpBox.offset + jxlpBox.size));
|
||||
offset = jxlpBox.offset + jxlpBox.size;
|
||||
}
|
||||
return partialStreams;
|
||||
}
|
||||
/** Concatenates partial codestreams into a single codestream */
|
||||
function concatenateCodestreams(partialCodestreams) {
|
||||
const totalLength = partialCodestreams.reduce((acc, curr) => acc + curr.length, 0);
|
||||
const codestream = new Uint8Array(totalLength);
|
||||
let position = 0;
|
||||
for (const partial of partialCodestreams) {
|
||||
codestream.set(partial, position);
|
||||
position += partial.length;
|
||||
}
|
||||
return codestream;
|
||||
}
|
||||
exports.JXL = {
|
||||
validate: (input) => {
|
||||
const boxType = (0, utils_1.toUTF8String)(input, 4, 8);
|
||||
if (boxType !== 'JXL ')
|
||||
return false;
|
||||
const ftypBox = (0, utils_1.findBox)(input, 'ftyp', 0);
|
||||
if (!ftypBox)
|
||||
return false;
|
||||
const brand = (0, utils_1.toUTF8String)(input, ftypBox.offset + 8, ftypBox.offset + 12);
|
||||
return brand === 'jxl ';
|
||||
},
|
||||
calculate(input) {
|
||||
const codestream = extractCodestream(input);
|
||||
if (codestream)
|
||||
return jxl_stream_1.JXLStream.calculate(codestream);
|
||||
throw new Error('No codestream found in JXL container');
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/ktx.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/ktx.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const KTX: IImage;
|
||||
19
node_modules/image-size/dist/types/ktx.js
generated
vendored
Normal file
19
node_modules/image-size/dist/types/ktx.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.KTX = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
exports.KTX = {
|
||||
validate: (input) => {
|
||||
const signature = (0, utils_1.toUTF8String)(input, 1, 7);
|
||||
return ['KTX 11', 'KTX 20'].includes(signature);
|
||||
},
|
||||
calculate: (input) => {
|
||||
const type = input[5] === 0x31 ? 'ktx' : 'ktx2';
|
||||
const offset = type === 'ktx' ? 36 : 20;
|
||||
return {
|
||||
height: (0, utils_1.readUInt32LE)(input, offset + 4),
|
||||
width: (0, utils_1.readUInt32LE)(input, offset),
|
||||
type,
|
||||
};
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/png.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/png.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const PNG: IImage;
|
||||
35
node_modules/image-size/dist/types/png.js
generated
vendored
Normal file
35
node_modules/image-size/dist/types/png.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PNG = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
const pngSignature = 'PNG\r\n\x1a\n';
|
||||
const pngImageHeaderChunkName = 'IHDR';
|
||||
// Used to detect "fried" png's: http://www.jongware.com/pngdefry.html
|
||||
const pngFriedChunkName = 'CgBI';
|
||||
exports.PNG = {
|
||||
validate(input) {
|
||||
if (pngSignature === (0, utils_1.toUTF8String)(input, 1, 8)) {
|
||||
let chunkName = (0, utils_1.toUTF8String)(input, 12, 16);
|
||||
if (chunkName === pngFriedChunkName) {
|
||||
chunkName = (0, utils_1.toUTF8String)(input, 28, 32);
|
||||
}
|
||||
if (chunkName !== pngImageHeaderChunkName) {
|
||||
throw new TypeError('Invalid PNG');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
calculate(input) {
|
||||
if ((0, utils_1.toUTF8String)(input, 12, 16) === pngFriedChunkName) {
|
||||
return {
|
||||
height: (0, utils_1.readUInt32BE)(input, 36),
|
||||
width: (0, utils_1.readUInt32BE)(input, 32),
|
||||
};
|
||||
}
|
||||
return {
|
||||
height: (0, utils_1.readUInt32BE)(input, 20),
|
||||
width: (0, utils_1.readUInt32BE)(input, 16),
|
||||
};
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/pnm.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/pnm.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const PNM: IImage;
|
||||
72
node_modules/image-size/dist/types/pnm.js
generated
vendored
Normal file
72
node_modules/image-size/dist/types/pnm.js
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PNM = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
const PNMTypes = {
|
||||
P1: 'pbm/ascii',
|
||||
P2: 'pgm/ascii',
|
||||
P3: 'ppm/ascii',
|
||||
P4: 'pbm',
|
||||
P5: 'pgm',
|
||||
P6: 'ppm',
|
||||
P7: 'pam',
|
||||
PF: 'pfm',
|
||||
};
|
||||
const handlers = {
|
||||
default: (lines) => {
|
||||
let dimensions = [];
|
||||
while (lines.length > 0) {
|
||||
const line = lines.shift();
|
||||
if (line[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
dimensions = line.split(' ');
|
||||
break;
|
||||
}
|
||||
if (dimensions.length === 2) {
|
||||
return {
|
||||
height: parseInt(dimensions[1], 10),
|
||||
width: parseInt(dimensions[0], 10),
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Invalid PNM');
|
||||
}
|
||||
},
|
||||
pam: (lines) => {
|
||||
const size = {};
|
||||
while (lines.length > 0) {
|
||||
const line = lines.shift();
|
||||
if (line.length > 16 || line.charCodeAt(0) > 128) {
|
||||
continue;
|
||||
}
|
||||
const [key, value] = line.split(' ');
|
||||
if (key && value) {
|
||||
size[key.toLowerCase()] = parseInt(value, 10);
|
||||
}
|
||||
if (size.height && size.width) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (size.height && size.width) {
|
||||
return {
|
||||
height: size.height,
|
||||
width: size.width,
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Invalid PAM');
|
||||
}
|
||||
},
|
||||
};
|
||||
exports.PNM = {
|
||||
validate: (input) => (0, utils_1.toUTF8String)(input, 0, 2) in PNMTypes,
|
||||
calculate(input) {
|
||||
const signature = (0, utils_1.toUTF8String)(input, 0, 2);
|
||||
const type = PNMTypes[signature];
|
||||
// TODO: this probably generates garbage. move to a stream based parser
|
||||
const lines = (0, utils_1.toUTF8String)(input, 3).split(/[\r\n]+/);
|
||||
const handler = handlers[type] || handlers.default;
|
||||
return handler(lines);
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/psd.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/psd.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const PSD: IImage;
|
||||
11
node_modules/image-size/dist/types/psd.js
generated
vendored
Normal file
11
node_modules/image-size/dist/types/psd.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PSD = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
exports.PSD = {
|
||||
validate: (input) => (0, utils_1.toUTF8String)(input, 0, 4) === '8BPS',
|
||||
calculate: (input) => ({
|
||||
height: (0, utils_1.readUInt32BE)(input, 14),
|
||||
width: (0, utils_1.readUInt32BE)(input, 18),
|
||||
}),
|
||||
};
|
||||
2
node_modules/image-size/dist/types/svg.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/svg.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const SVG: IImage;
|
||||
90
node_modules/image-size/dist/types/svg.js
generated
vendored
Normal file
90
node_modules/image-size/dist/types/svg.js
generated
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SVG = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
const svgReg = /<svg\s([^>"']|"[^"]*"|'[^']*')*>/;
|
||||
const extractorRegExps = {
|
||||
height: /\sheight=(['"])([^%]+?)\1/,
|
||||
root: svgReg,
|
||||
viewbox: /\sviewBox=(['"])(.+?)\1/i,
|
||||
width: /\swidth=(['"])([^%]+?)\1/,
|
||||
};
|
||||
const INCH_CM = 2.54;
|
||||
const units = {
|
||||
in: 96,
|
||||
cm: 96 / INCH_CM,
|
||||
em: 16,
|
||||
ex: 8,
|
||||
m: (96 / INCH_CM) * 100,
|
||||
mm: 96 / INCH_CM / 10,
|
||||
pc: 96 / 72 / 12,
|
||||
pt: 96 / 72,
|
||||
px: 1,
|
||||
};
|
||||
const unitsReg = new RegExp(`^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join('|')})?$`);
|
||||
function parseLength(len) {
|
||||
const m = unitsReg.exec(len);
|
||||
if (!m) {
|
||||
return undefined;
|
||||
}
|
||||
return Math.round(Number(m[1]) * (units[m[2]] || 1));
|
||||
}
|
||||
function parseViewbox(viewbox) {
|
||||
const bounds = viewbox.split(' ');
|
||||
return {
|
||||
height: parseLength(bounds[3]),
|
||||
width: parseLength(bounds[2]),
|
||||
};
|
||||
}
|
||||
function parseAttributes(root) {
|
||||
const width = root.match(extractorRegExps.width);
|
||||
const height = root.match(extractorRegExps.height);
|
||||
const viewbox = root.match(extractorRegExps.viewbox);
|
||||
return {
|
||||
height: height && parseLength(height[2]),
|
||||
viewbox: viewbox && parseViewbox(viewbox[2]),
|
||||
width: width && parseLength(width[2]),
|
||||
};
|
||||
}
|
||||
function calculateByDimensions(attrs) {
|
||||
return {
|
||||
height: attrs.height,
|
||||
width: attrs.width,
|
||||
};
|
||||
}
|
||||
function calculateByViewbox(attrs, viewbox) {
|
||||
const ratio = viewbox.width / viewbox.height;
|
||||
if (attrs.width) {
|
||||
return {
|
||||
height: Math.floor(attrs.width / ratio),
|
||||
width: attrs.width,
|
||||
};
|
||||
}
|
||||
if (attrs.height) {
|
||||
return {
|
||||
height: attrs.height,
|
||||
width: Math.floor(attrs.height * ratio),
|
||||
};
|
||||
}
|
||||
return {
|
||||
height: viewbox.height,
|
||||
width: viewbox.width,
|
||||
};
|
||||
}
|
||||
exports.SVG = {
|
||||
// Scan only the first kilo-byte to speed up the check on larger files
|
||||
validate: (input) => svgReg.test((0, utils_1.toUTF8String)(input, 0, 1000)),
|
||||
calculate(input) {
|
||||
const root = (0, utils_1.toUTF8String)(input).match(extractorRegExps.root);
|
||||
if (root) {
|
||||
const attrs = parseAttributes(root[0]);
|
||||
if (attrs.width && attrs.height) {
|
||||
return calculateByDimensions(attrs);
|
||||
}
|
||||
if (attrs.viewbox) {
|
||||
return calculateByViewbox(attrs, attrs.viewbox);
|
||||
}
|
||||
}
|
||||
throw new TypeError('Invalid SVG');
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/tga.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/tga.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const TGA: IImage;
|
||||
15
node_modules/image-size/dist/types/tga.js
generated
vendored
Normal file
15
node_modules/image-size/dist/types/tga.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TGA = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
exports.TGA = {
|
||||
validate(input) {
|
||||
return (0, utils_1.readUInt16LE)(input, 0) === 0 && (0, utils_1.readUInt16LE)(input, 4) === 0;
|
||||
},
|
||||
calculate(input) {
|
||||
return {
|
||||
height: (0, utils_1.readUInt16LE)(input, 14),
|
||||
width: (0, utils_1.readUInt16LE)(input, 12),
|
||||
};
|
||||
},
|
||||
};
|
||||
2
node_modules/image-size/dist/types/tiff.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/tiff.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const TIFF: IImage;
|
||||
95
node_modules/image-size/dist/types/tiff.js
generated
vendored
Normal file
95
node_modules/image-size/dist/types/tiff.js
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TIFF = void 0;
|
||||
// based on http://www.compix.com/fileformattif.htm
|
||||
// TO-DO: support big-endian as well
|
||||
const fs = require("fs");
|
||||
const utils_1 = require("./utils");
|
||||
// Read IFD (image-file-directory) into a buffer
|
||||
function readIFD(input, filepath, isBigEndian) {
|
||||
const ifdOffset = (0, utils_1.readUInt)(input, 32, 4, isBigEndian);
|
||||
// read only till the end of the file
|
||||
let bufferSize = 1024;
|
||||
const fileSize = fs.statSync(filepath).size;
|
||||
if (ifdOffset + bufferSize > fileSize) {
|
||||
bufferSize = fileSize - ifdOffset - 10;
|
||||
}
|
||||
// populate the buffer
|
||||
const endBuffer = new Uint8Array(bufferSize);
|
||||
const descriptor = fs.openSync(filepath, 'r');
|
||||
fs.readSync(descriptor, endBuffer, 0, bufferSize, ifdOffset);
|
||||
fs.closeSync(descriptor);
|
||||
return endBuffer.slice(2);
|
||||
}
|
||||
// TIFF values seem to be messed up on Big-Endian, this helps
|
||||
function readValue(input, isBigEndian) {
|
||||
const low = (0, utils_1.readUInt)(input, 16, 8, isBigEndian);
|
||||
const high = (0, utils_1.readUInt)(input, 16, 10, isBigEndian);
|
||||
return (high << 16) + low;
|
||||
}
|
||||
// move to the next tag
|
||||
function nextTag(input) {
|
||||
if (input.length > 24) {
|
||||
return input.slice(12);
|
||||
}
|
||||
}
|
||||
// Extract IFD tags from TIFF metadata
|
||||
function extractTags(input, isBigEndian) {
|
||||
const tags = {};
|
||||
let temp = input;
|
||||
while (temp && temp.length) {
|
||||
const code = (0, utils_1.readUInt)(temp, 16, 0, isBigEndian);
|
||||
const type = (0, utils_1.readUInt)(temp, 16, 2, isBigEndian);
|
||||
const length = (0, utils_1.readUInt)(temp, 32, 4, isBigEndian);
|
||||
// 0 means end of IFD
|
||||
if (code === 0) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// 256 is width, 257 is height
|
||||
// if (code === 256 || code === 257) {
|
||||
if (length === 1 && (type === 3 || type === 4)) {
|
||||
tags[code] = readValue(temp, isBigEndian);
|
||||
}
|
||||
// move to the next tag
|
||||
temp = nextTag(temp);
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
// Test if the TIFF is Big Endian or Little Endian
|
||||
function determineEndianness(input) {
|
||||
const signature = (0, utils_1.toUTF8String)(input, 0, 2);
|
||||
if ('II' === signature) {
|
||||
return 'LE';
|
||||
}
|
||||
else if ('MM' === signature) {
|
||||
return 'BE';
|
||||
}
|
||||
}
|
||||
const signatures = [
|
||||
// '492049', // currently not supported
|
||||
'49492a00', // Little endian
|
||||
'4d4d002a', // Big Endian
|
||||
// '4d4d002a', // BigTIFF > 4GB. currently not supported
|
||||
];
|
||||
exports.TIFF = {
|
||||
validate: (input) => signatures.includes((0, utils_1.toHexString)(input, 0, 4)),
|
||||
calculate(input, filepath) {
|
||||
if (!filepath) {
|
||||
throw new TypeError("Tiff doesn't support buffer");
|
||||
}
|
||||
// Determine BE/LE
|
||||
const isBigEndian = determineEndianness(input) === 'BE';
|
||||
// read the IFD
|
||||
const ifdBuffer = readIFD(input, filepath, isBigEndian);
|
||||
// extract the tags from the IFD
|
||||
const tags = extractTags(ifdBuffer, isBigEndian);
|
||||
const width = tags[256];
|
||||
const height = tags[257];
|
||||
if (!width || !height) {
|
||||
throw new TypeError('Invalid Tiff. Missing tags');
|
||||
}
|
||||
return { height, width };
|
||||
},
|
||||
};
|
||||
15
node_modules/image-size/dist/types/utils.d.ts
generated
vendored
Normal file
15
node_modules/image-size/dist/types/utils.d.ts
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
export declare const toUTF8String: (input: Uint8Array, start?: number, end?: number) => string;
|
||||
export declare const toHexString: (input: Uint8Array, start?: number, end?: number) => string;
|
||||
export declare const readInt16LE: (input: Uint8Array, offset?: number) => number;
|
||||
export declare const readUInt16BE: (input: Uint8Array, offset?: number) => number;
|
||||
export declare const readUInt16LE: (input: Uint8Array, offset?: number) => number;
|
||||
export declare const readUInt24LE: (input: Uint8Array, offset?: number) => number;
|
||||
export declare const readInt32LE: (input: Uint8Array, offset?: number) => number;
|
||||
export declare const readUInt32BE: (input: Uint8Array, offset?: number) => number;
|
||||
export declare const readUInt32LE: (input: Uint8Array, offset?: number) => number;
|
||||
export declare function readUInt(input: Uint8Array, bits: 16 | 32, offset: number, isBigEndian: boolean): number;
|
||||
export declare function findBox(input: Uint8Array, boxName: string, offset: number): {
|
||||
name: string;
|
||||
offset: number;
|
||||
size: number;
|
||||
} | undefined;
|
||||
75
node_modules/image-size/dist/types/utils.js
generated
vendored
Normal file
75
node_modules/image-size/dist/types/utils.js
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.findBox = exports.readUInt = exports.readUInt32LE = exports.readUInt32BE = exports.readInt32LE = exports.readUInt24LE = exports.readUInt16LE = exports.readUInt16BE = exports.readInt16LE = exports.toHexString = exports.toUTF8String = void 0;
|
||||
const decoder = new TextDecoder();
|
||||
const toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end));
|
||||
exports.toUTF8String = toUTF8String;
|
||||
const toHexString = (input, start = 0, end = input.length) => input
|
||||
.slice(start, end)
|
||||
.reduce((memo, i) => memo + ('0' + i.toString(16)).slice(-2), '');
|
||||
exports.toHexString = toHexString;
|
||||
const readInt16LE = (input, offset = 0) => {
|
||||
const val = input[offset] + input[offset + 1] * 2 ** 8;
|
||||
return val | ((val & (2 ** 15)) * 0x1fffe);
|
||||
};
|
||||
exports.readInt16LE = readInt16LE;
|
||||
const readUInt16BE = (input, offset = 0) => input[offset] * 2 ** 8 + input[offset + 1];
|
||||
exports.readUInt16BE = readUInt16BE;
|
||||
const readUInt16LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8;
|
||||
exports.readUInt16LE = readUInt16LE;
|
||||
const readUInt24LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8 + input[offset + 2] * 2 ** 16;
|
||||
exports.readUInt24LE = readUInt24LE;
|
||||
const readInt32LE = (input, offset = 0) => input[offset] +
|
||||
input[offset + 1] * 2 ** 8 +
|
||||
input[offset + 2] * 2 ** 16 +
|
||||
(input[offset + 3] << 24);
|
||||
exports.readInt32LE = readInt32LE;
|
||||
const readUInt32BE = (input, offset = 0) => input[offset] * 2 ** 24 +
|
||||
input[offset + 1] * 2 ** 16 +
|
||||
input[offset + 2] * 2 ** 8 +
|
||||
input[offset + 3];
|
||||
exports.readUInt32BE = readUInt32BE;
|
||||
const readUInt32LE = (input, offset = 0) => input[offset] +
|
||||
input[offset + 1] * 2 ** 8 +
|
||||
input[offset + 2] * 2 ** 16 +
|
||||
input[offset + 3] * 2 ** 24;
|
||||
exports.readUInt32LE = readUInt32LE;
|
||||
// Abstract reading multi-byte unsigned integers
|
||||
const methods = {
|
||||
readUInt16BE: exports.readUInt16BE,
|
||||
readUInt16LE: exports.readUInt16LE,
|
||||
readUInt32BE: exports.readUInt32BE,
|
||||
readUInt32LE: exports.readUInt32LE,
|
||||
};
|
||||
function readUInt(input, bits, offset, isBigEndian) {
|
||||
offset = offset || 0;
|
||||
const endian = isBigEndian ? 'BE' : 'LE';
|
||||
const methodName = ('readUInt' + bits + endian);
|
||||
return methods[methodName](input, offset);
|
||||
}
|
||||
exports.readUInt = readUInt;
|
||||
function readBox(input, offset) {
|
||||
if (input.length - offset < 4)
|
||||
return;
|
||||
const boxSize = (0, exports.readUInt32BE)(input, offset);
|
||||
if (input.length - offset < boxSize)
|
||||
return;
|
||||
return {
|
||||
name: (0, exports.toUTF8String)(input, 4 + offset, 8 + offset),
|
||||
offset,
|
||||
size: boxSize,
|
||||
};
|
||||
}
|
||||
function findBox(input, boxName, offset) {
|
||||
while (offset < input.length) {
|
||||
const box = readBox(input, offset);
|
||||
if (!box)
|
||||
break;
|
||||
if (box.name === boxName)
|
||||
return box;
|
||||
// Fix the infinite loop by ensuring offset always increases
|
||||
// If box.size is 0, advance by at least 8 bytes (the size of the box header)
|
||||
offset += box.size > 0 ? box.size : 8;
|
||||
}
|
||||
}
|
||||
exports.findBox = findBox;
|
||||
2
node_modules/image-size/dist/types/webp.d.ts
generated
vendored
Normal file
2
node_modules/image-size/dist/types/webp.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { IImage } from './interface';
|
||||
export declare const WEBP: IImage;
|
||||
60
node_modules/image-size/dist/types/webp.js
generated
vendored
Normal file
60
node_modules/image-size/dist/types/webp.js
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WEBP = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
function calculateExtended(input) {
|
||||
return {
|
||||
height: 1 + (0, utils_1.readUInt24LE)(input, 7),
|
||||
width: 1 + (0, utils_1.readUInt24LE)(input, 4),
|
||||
};
|
||||
}
|
||||
function calculateLossless(input) {
|
||||
return {
|
||||
height: 1 +
|
||||
(((input[4] & 0xf) << 10) | (input[3] << 2) | ((input[2] & 0xc0) >> 6)),
|
||||
width: 1 + (((input[2] & 0x3f) << 8) | input[1]),
|
||||
};
|
||||
}
|
||||
function calculateLossy(input) {
|
||||
// `& 0x3fff` returns the last 14 bits
|
||||
// TO-DO: include webp scaling in the calculations
|
||||
return {
|
||||
height: (0, utils_1.readInt16LE)(input, 8) & 0x3fff,
|
||||
width: (0, utils_1.readInt16LE)(input, 6) & 0x3fff,
|
||||
};
|
||||
}
|
||||
exports.WEBP = {
|
||||
validate(input) {
|
||||
const riffHeader = 'RIFF' === (0, utils_1.toUTF8String)(input, 0, 4);
|
||||
const webpHeader = 'WEBP' === (0, utils_1.toUTF8String)(input, 8, 12);
|
||||
const vp8Header = 'VP8' === (0, utils_1.toUTF8String)(input, 12, 15);
|
||||
return riffHeader && webpHeader && vp8Header;
|
||||
},
|
||||
calculate(input) {
|
||||
const chunkHeader = (0, utils_1.toUTF8String)(input, 12, 16);
|
||||
input = input.slice(20, 30);
|
||||
// Extended webp stream signature
|
||||
if (chunkHeader === 'VP8X') {
|
||||
const extendedHeader = input[0];
|
||||
const validStart = (extendedHeader & 0xc0) === 0;
|
||||
const validEnd = (extendedHeader & 0x01) === 0;
|
||||
if (validStart && validEnd) {
|
||||
return calculateExtended(input);
|
||||
}
|
||||
else {
|
||||
// TODO: breaking change
|
||||
throw new TypeError('Invalid WebP');
|
||||
}
|
||||
}
|
||||
// Lossless webp stream signature
|
||||
if (chunkHeader === 'VP8 ' && input[0] !== 0x2f) {
|
||||
return calculateLossy(input);
|
||||
}
|
||||
// Lossy webp stream signature
|
||||
const signature = (0, utils_1.toHexString)(input, 3, 6);
|
||||
if (chunkHeader === 'VP8L' && signature !== '9d012a') {
|
||||
return calculateLossless(input);
|
||||
}
|
||||
throw new TypeError('Invalid WebP');
|
||||
},
|
||||
};
|
||||
10
node_modules/image-size/dist/utils/bit-reader.d.ts
generated
vendored
Normal file
10
node_modules/image-size/dist/utils/bit-reader.d.ts
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/** This class helps read Uint8Array bit-by-bit */
|
||||
export declare class BitReader {
|
||||
private readonly input;
|
||||
private readonly endianness;
|
||||
private byteOffset;
|
||||
private bitOffset;
|
||||
constructor(input: Uint8Array, endianness: 'big-endian' | 'little-endian');
|
||||
/** Reads a specified number of bits, and move the offset */
|
||||
getBits(length?: number): number;
|
||||
}
|
||||
44
node_modules/image-size/dist/utils/bit-reader.js
generated
vendored
Normal file
44
node_modules/image-size/dist/utils/bit-reader.js
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BitReader = void 0;
|
||||
/** This class helps read Uint8Array bit-by-bit */
|
||||
class BitReader {
|
||||
constructor(input, endianness) {
|
||||
this.input = input;
|
||||
this.endianness = endianness;
|
||||
// Skip the first 16 bits (2 bytes) of signature
|
||||
this.byteOffset = 2;
|
||||
this.bitOffset = 0;
|
||||
}
|
||||
/** Reads a specified number of bits, and move the offset */
|
||||
getBits(length = 1) {
|
||||
let result = 0;
|
||||
let bitsRead = 0;
|
||||
while (bitsRead < length) {
|
||||
if (this.byteOffset >= this.input.length) {
|
||||
throw new Error('Reached end of input');
|
||||
}
|
||||
const currentByte = this.input[this.byteOffset];
|
||||
const bitsLeft = 8 - this.bitOffset;
|
||||
const bitsToRead = Math.min(length - bitsRead, bitsLeft);
|
||||
if (this.endianness === 'little-endian') {
|
||||
const mask = (1 << bitsToRead) - 1;
|
||||
const bits = (currentByte >> this.bitOffset) & mask;
|
||||
result |= bits << bitsRead;
|
||||
}
|
||||
else {
|
||||
const mask = ((1 << bitsToRead) - 1) << (8 - this.bitOffset - bitsToRead);
|
||||
const bits = (currentByte & mask) >> (8 - this.bitOffset - bitsToRead);
|
||||
result = (result << bitsToRead) | bits;
|
||||
}
|
||||
bitsRead += bitsToRead;
|
||||
this.bitOffset += bitsToRead;
|
||||
if (this.bitOffset === 8) {
|
||||
this.byteOffset++;
|
||||
this.bitOffset = 0;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
exports.BitReader = BitReader;
|
||||
81
node_modules/image-size/package.json
generated
vendored
Normal file
81
node_modules/image-size/package.json
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
{
|
||||
"name": "image-size",
|
||||
"version": "1.2.1",
|
||||
"description": "get dimensions of any image file",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"bin/image-size.js"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=16.x"
|
||||
},
|
||||
"packageManager": "yarn@4.0.2",
|
||||
"bin": "bin/image-size.js",
|
||||
"scripts": {
|
||||
"lint": "eslint bin lib specs",
|
||||
"format": "prettier --write lib specs eslint.config.mjs",
|
||||
"test": "nyc mocha",
|
||||
"clean": "rm -rf dist docs",
|
||||
"generate-docs": "typedoc",
|
||||
"build": "tsc",
|
||||
"prepack": "yarn clean && yarn 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": "git://github.com/image-size/image-size.git",
|
||||
"author": "netroy <aditya@netroy.in> (http://netroy.in/)",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "9.5.0",
|
||||
"@types/chai": "4.3.16",
|
||||
"@types/eslint__js": "8.42.3",
|
||||
"@types/glob": "8.1.0",
|
||||
"@types/mocha": "10.0.7",
|
||||
"@types/node": "18.19.39",
|
||||
"@types/sinon": "17.0.3",
|
||||
"chai": "4.4.1",
|
||||
"eslint": "8.57.0",
|
||||
"eslint-config-prettier": "9.1.0",
|
||||
"eslint-plugin-prettier": "5.1.3",
|
||||
"glob": "10.4.2",
|
||||
"mocha": "10.2.0",
|
||||
"nyc": "15.1.0",
|
||||
"prettier": "3.3.2",
|
||||
"sinon": "17.0.1",
|
||||
"ts-node": "10.9.2",
|
||||
"typedoc": "0.25.13",
|
||||
"typescript": "5.4.5",
|
||||
"typescript-eslint": "7.13.1"
|
||||
},
|
||||
"nyc": {
|
||||
"include": "lib",
|
||||
"exclude": "specs/*.spec.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"queue": "6.0.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user