image-size
Advanced tools
Comparing version 1.1.1 to 1.2.0
#!/usr/bin/env node | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
'use strict' | ||
@@ -31,3 +32,3 @@ | ||
const sizes = size.images || [size] | ||
sizes.forEach(size => { | ||
sizes.forEach((size) => { | ||
let greyType = '' | ||
@@ -38,8 +39,12 @@ if (size.type) { | ||
console.info( | ||
colorize(size.width, green) + greyX + colorize(size.height, green) | ||
+ ' - ' + greyImage + greyType | ||
colorize(size.width, green) + | ||
greyX + | ||
colorize(size.height, green) + | ||
' - ' + | ||
greyImage + | ||
greyType, | ||
) | ||
}) | ||
} else { | ||
console.error('file doesn\'t exist - ', image) | ||
console.error("file doesn't exist - ", image) | ||
} | ||
@@ -46,0 +51,0 @@ } catch (e) { |
@@ -8,3 +8,3 @@ "use strict"; | ||
mif1: 'heif', | ||
msf1: 'heif', // hief-sequence | ||
msf1: 'heif', // heif-sequence | ||
heic: 'heic', | ||
@@ -16,22 +16,27 @@ heix: 'heic', | ||
exports.HEIF = { | ||
validate(buffer) { | ||
const ftype = (0, utils_1.toUTF8String)(buffer, 4, 8); | ||
const brand = (0, utils_1.toUTF8String)(buffer, 8, 12); | ||
return 'ftyp' === ftype && brand in brandMap; | ||
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(buffer) { | ||
calculate(input) { | ||
// Based on https://nokiatech.github.io/heif/technical.html | ||
const metaBox = (0, utils_1.findBox)(buffer, 'meta', 0); | ||
const iprpBox = metaBox && (0, utils_1.findBox)(buffer, 'iprp', metaBox.offset + 12); | ||
const ipcoBox = iprpBox && (0, utils_1.findBox)(buffer, 'ipco', iprpBox.offset + 8); | ||
const ispeBox = ipcoBox && (0, utils_1.findBox)(buffer, 'ispe', ipcoBox.offset + 8); | ||
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)(buffer, ispeBox.offset + 16), | ||
width: (0, utils_1.readUInt32BE)(buffer, ispeBox.offset + 12), | ||
type: (0, utils_1.toUTF8String)(buffer, 8, 12), | ||
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'); | ||
} | ||
}, | ||
}; |
@@ -12,2 +12,4 @@ export declare const typeHandlers: { | ||
jpg: import("./interface").IImage; | ||
jxl: import("./interface").IImage; | ||
'jxl-stream': import("./interface").IImage; | ||
ktx: import("./interface").IImage; | ||
@@ -14,0 +16,0 @@ png: import("./interface").IImage; |
@@ -15,2 +15,4 @@ "use strict"; | ||
const jpg_1 = require("./jpg"); | ||
const jxl_1 = require("./jxl"); | ||
const jxl_stream_1 = require("./jxl-stream"); | ||
const ktx_1 = require("./ktx"); | ||
@@ -35,2 +37,4 @@ const png_1 = require("./png"); | ||
jpg: jpg_1.JPG, | ||
jxl: jxl_1.JXL, | ||
'jxl-stream': jxl_stream_1.JXLStream, | ||
ktx: ktx_1.KTX, | ||
@@ -37,0 +41,0 @@ png: png_1.PNG, |
@@ -1,2 +0,2 @@ | ||
export type ISize = { | ||
export interface ISize { | ||
width: number | undefined; | ||
@@ -6,9 +6,9 @@ height: number | undefined; | ||
type?: string; | ||
}; | ||
} | ||
export type ISizeCalculationResult = { | ||
images?: ISize[]; | ||
} & ISize; | ||
export type IImage = { | ||
export interface IImage { | ||
validate: (input: Uint8Array) => boolean; | ||
calculate: (input: Uint8Array, filepath?: string) => ISizeCalculationResult; | ||
}; | ||
} |
@@ -7,3 +7,3 @@ "use strict"; | ||
// TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC | ||
validate: (input) => (0, utils_1.toHexString)(input, 0, 4) === 'ff4fff51', | ||
validate: (input) => (0, utils_1.readUInt32BE)(input, 0) === 0xff4fff51, | ||
calculate: (input) => ({ | ||
@@ -10,0 +10,0 @@ height: (0, utils_1.readUInt32BE)(input, 12), |
@@ -7,3 +7,4 @@ "use strict"; | ||
validate(input) { | ||
if ((0, utils_1.readUInt32BE)(input, 4) !== 0x6a502020 || (0, utils_1.readUInt32BE)(input, 0) < 1) | ||
const boxType = (0, utils_1.toUTF8String)(input, 4, 8); | ||
if (boxType !== 'jP ') | ||
return false; | ||
@@ -13,3 +14,4 @@ const ftypBox = (0, utils_1.findBox)(input, 'ftyp', 0); | ||
return false; | ||
return (0, utils_1.readUInt32BE)(input, ftypBox.offset + 4) === 0x66747970; | ||
const brand = (0, utils_1.toUTF8String)(input, ftypBox.offset + 8, ftypBox.offset + 12); | ||
return brand === 'jp2 '; | ||
}, | ||
@@ -16,0 +18,0 @@ calculate(input) { |
@@ -13,8 +13,8 @@ "use strict"; | ||
const offset = type === 'ktx' ? 36 : 20; | ||
return ({ | ||
return { | ||
height: (0, utils_1.readUInt32LE)(input, offset + 4), | ||
width: (0, utils_1.readUInt32LE)(input, offset), | ||
type, | ||
}); | ||
}; | ||
}, | ||
}; |
@@ -80,3 +80,3 @@ "use strict"; | ||
if (!filepath) { | ||
throw new TypeError('Tiff doesn\'t support buffer'); | ||
throw new TypeError("Tiff doesn't support buffer"); | ||
} | ||
@@ -83,0 +83,0 @@ // Determine BE/LE |
@@ -11,3 +11,3 @@ export declare const toUTF8String: (input: Uint8Array, start?: number, end?: number) => string; | ||
export declare function readUInt(input: Uint8Array, bits: 16 | 32, offset: number, isBigEndian: boolean): number; | ||
export declare function findBox(buffer: Uint8Array, boxName: string, offset: number): { | ||
export declare function findBox(input: Uint8Array, boxName: string, offset: number): { | ||
name: string; | ||
@@ -14,0 +14,0 @@ offset: number; |
@@ -51,10 +51,10 @@ "use strict"; | ||
exports.readUInt = readUInt; | ||
function readBox(buffer, offset) { | ||
if (buffer.length - offset < 4) | ||
function readBox(input, offset) { | ||
if (input.length - offset < 4) | ||
return; | ||
const boxSize = (0, exports.readUInt32BE)(buffer, offset); | ||
if (buffer.length - offset < boxSize) | ||
const boxSize = (0, exports.readUInt32BE)(input, offset); | ||
if (input.length - offset < boxSize) | ||
return; | ||
return { | ||
name: (0, exports.toUTF8String)(buffer, 4 + offset, 8 + offset), | ||
name: (0, exports.toUTF8String)(input, 4 + offset, 8 + offset), | ||
offset, | ||
@@ -64,5 +64,5 @@ size: boxSize, | ||
} | ||
function findBox(buffer, boxName, offset) { | ||
while (offset < buffer.length) { | ||
const box = readBox(buffer, offset); | ||
function findBox(input, boxName, offset) { | ||
while (offset < input.length) { | ||
const box = readBox(input, offset); | ||
if (!box) | ||
@@ -69,0 +69,0 @@ break; |
{ | ||
"name": "image-size", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "get dimensions of any image file", | ||
@@ -17,4 +17,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"lint": "eslint --ext .ts,.js bin lib specs", | ||
"format": "prettier --write lib specs", | ||
"lint": "eslint bin lib specs", | ||
"format": "prettier --write lib specs eslint.config.mjs", | ||
"test": "nyc mocha", | ||
@@ -42,2 +42,3 @@ "clean": "rm -rf dist docs", | ||
"jpeg", | ||
"jxl", | ||
"png", | ||
@@ -54,21 +55,22 @@ "psd", | ||
"devDependencies": { | ||
"@types/chai": "4.3.11", | ||
"@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.6", | ||
"@types/node": "18.19.3", | ||
"@types/sinon": "17.0.2", | ||
"@typescript-eslint/eslint-plugin": "6.16.0", | ||
"@typescript-eslint/parser": "6.16.0", | ||
"chai": "4.3.10", | ||
"eslint": "8.56.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.2", | ||
"glob": "10.3.10", | ||
"eslint-plugin-prettier": "5.1.3", | ||
"glob": "10.4.2", | ||
"mocha": "10.2.0", | ||
"nyc": "15.1.0", | ||
"prettier": "3.1.1", | ||
"prettier": "3.3.2", | ||
"sinon": "17.0.1", | ||
"ts-node": "10.9.2", | ||
"typedoc": "0.25.4", | ||
"typescript": "5.3.3" | ||
"typedoc": "0.25.13", | ||
"typescript": "5.4.5", | ||
"typescript-eslint": "7.13.1" | ||
}, | ||
@@ -75,0 +77,0 @@ "nyc": { |
@@ -19,4 +19,5 @@ # image-size | ||
- J2C | ||
- JP2 | ||
- JPEG-2000 (JP2) | ||
- JPEG | ||
- JPEG-XL | ||
- KTX (1 and 2) | ||
@@ -23,0 +24,0 @@ - PNG |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56607
56
1407
185
20