Socket
Socket
Sign inDemoInstall

image-size

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-size - npm Package Compare versions

Comparing version 0.8.3 to 0.9.1

49

bin/image-size.js
#!/usr/bin/env node
'use strict';
'use strict'
const fs = require('fs');
const path = require('path');
const { imageSize } = require('..');
const fs = require('fs')
const path = require('path')
const { imageSize } = require('..')
const files = process.argv.slice(2);
const files = process.argv.slice(2)
if (!files.length) {
console.error('Usage: image-size image1 [image2] [image3] ...');
process.exit(-1);
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'];
const red = ['\x1B[31m', '\x1B[39m']
// const bold = ['\x1B[1m', '\x1B[22m']
const grey = ['\x1B[90m', '\x1B[39m']
const green = ['\x1B[32m', '\x1B[39m']

@@ -27,22 +27,23 @@ function colorize(text, color) {

if (fs.existsSync(path.resolve(image))) {
let size = imageSize(image);
let greyX = colorize('x', grey);
let greyImage = colorize(image, grey);
(size.images || [size]).forEach(function (size) {
let greyType = '';
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);
greyType = colorize(' (' + size.type + ')', grey)
}
console.info(
colorize(size.width, green) + greyX + colorize(size.height, green)
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)
}
} catch (e) {
// console.error(e.stack);
console.error(colorize(e.message, red), '-', image);
// console.error(e.stack)
console.error(colorize(e.message, red), '-', image)
}
});
})
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.detector = void 0;
const types_1 = require("./types");

@@ -4,0 +5,0 @@ const keys = Object.keys(types_1.typeHandlers);

/// <reference types="node" />
import { ISizeCalculationResult } from './types/interface';
import './fs.promises';
declare type CallbackFn = (e: Error | null, r?: ISizeCalculationResult) => void;

@@ -5,0 +4,0 @@ export declare function imageSize(input: Buffer | string): ISizeCalculationResult;

@@ -12,2 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.types = exports.setConcurrency = exports.imageSize = void 0;
const fs = require("fs");

@@ -18,3 +19,2 @@ const path = require("path");

const detector_1 = require("./detector");
require("./fs.promises");
// Maximum buffer size, with a default of 512 kilobytes.

@@ -81,2 +81,3 @@ // TO-DO: make this adaptive based on the initial signature of the image

}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
module.exports = exports = imageSize; // backwards compatibility

@@ -83,0 +84,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readUInt = void 0;
// Abstract reading multi-byte unsigned integers

@@ -8,5 +9,4 @@ function readUInt(buffer, bits, offset, isBigEndian) {

const methodName = ('readUInt' + bits + endian);
const method = buffer[methodName];
return method.call(buffer, offset);
return buffer[methodName].call(buffer, offset);
}
exports.readUInt = readUInt;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.typeHandlers = void 0;
const bmp_1 = require("./types/bmp");

@@ -4,0 +5,0 @@ const cur_1 = require("./types/cur");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BMP = void 0;
exports.BMP = {

@@ -4,0 +5,0 @@ validate(buffer) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CUR = void 0;
const ico_1 = require("./ico");

@@ -4,0 +5,0 @@ const TYPE_CURSOR = 2;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DDS = void 0;
exports.DDS = {

@@ -4,0 +5,0 @@ validate(buffer) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GIF = void 0;
const gifRegexp = /^GIF8[79]a/;

@@ -4,0 +5,0 @@ exports.GIF = {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ICNS = void 0;
/**

@@ -22,3 +23,2 @@ * ICNS Header

const ENTRY_LENGTH_OFFSET = 4; // MSB => BIG ENDIAN
/* tslint:disable:object-literal-sort-keys */
const ICON_TYPE_SIZE = {

@@ -66,3 +66,2 @@ ICON: 32,

};
/* tslint:enable:object-literal-sort-keys */
function readImageHeader(buffer, imageOffset) {

@@ -69,0 +68,0 @@ const imageLengthOffset = imageOffset + ENTRY_LENGTH_OFFSET;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ICO = void 0;
const TYPE_ICON = 1;

@@ -4,0 +5,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.J2C = void 0;
exports.J2C = {

@@ -4,0 +5,0 @@ validate(buffer) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JP2 = void 0;
const BoxTypes = {

@@ -47,2 +48,3 @@ ftyp: '66747970',

// WHAT ARE THESE 4 BYTES?????
// eslint-disable-next-line no-case-declarations
const MAGIC = 4;

@@ -49,0 +51,0 @@ offset = offset + 4 + MAGIC + calculateRREQLength(buffer.slice(offset + 4));

@@ -7,2 +7,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.JPG = void 0;
const readUInt_1 = require("../readUInt");

@@ -27,14 +28,2 @@ const EXIF_MARKER = '45786966';

}
function validateExifBlock(buffer, index) {
// Skip APP1 Data Size
const exifBlock = buffer.slice(APP1_DATA_SIZE_BYTES, index);
// Consider byte alignment
const byteAlign = exifBlock.toString('hex', 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 extractOrientation(exifBlock, isBigEndian) {

@@ -75,2 +64,14 @@ // TODO: assert that this contains 0x002A

}
function validateExifBlock(buffer, index) {
// Skip APP1 Data Size
const exifBlock = buffer.slice(APP1_DATA_SIZE_BYTES, index);
// Consider byte alignment
const byteAlign = exifBlock.toString('hex', 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 validateBuffer(buffer, index) {

@@ -77,0 +78,0 @@ // index should be within buffer limits

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KTX = void 0;
const SIGNATURE = 'KTX 11';

@@ -4,0 +5,0 @@ exports.KTX = {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PNG = void 0;
const pngSignature = 'PNG\r\n\x1a\n';

@@ -4,0 +5,0 @@ const pngImageHeaderChunkName = 'IHDR';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PNM = void 0;
const PNMTypes = {

@@ -4,0 +5,0 @@ P1: 'pbm/ascii',

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PSD = void 0;
exports.PSD = {

@@ -4,0 +5,0 @@ validate(buffer) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SVG = void 0;
const svgReg = /<svg\s([^>"']|"[^"]*"|'[^']*')*>/;

@@ -4,0 +5,0 @@ const extractorRegExps = {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TIFF = void 0;
// based on http://www.compix.com/fileformattif.htm

@@ -20,2 +21,3 @@ // TO-DO: support big-endian as well

fs.readSync(descriptor, endBuffer, 0, bufferSize, ifdOffset);
fs.closeSync(descriptor);
return endBuffer.slice(2);

@@ -22,0 +24,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WEBP = void 0;
function calculateExtended(buffer) {

@@ -4,0 +5,0 @@ return {

{
"name": "image-size",
"version": "0.8.3",
"version": "0.9.1",
"description": "get dimensions of any image file",

@@ -12,3 +12,3 @@ "main": "dist/index.js",

"engines": {
"node": ">=6.9.0"
"node": ">=10.18.0"
},

@@ -19,10 +19,10 @@ "bin": {

"scripts": {
"pretest": "tslint -p . && tsc && eslint specs",
"test": "nyc mocha specs",
"pretest": "eslint --ext .ts,.js bin lib specs",
"test": "nyc mocha",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"clean": "rm -rf dist",
"clean": "rm -rf dist docs",
"generate-docs": "typedoc",
"build": "tsc",
"prepack": "npm run clean && npm run build"
},
"repository": "image-size/image-size",
"keywords": [

@@ -47,15 +47,23 @@ "image",

],
"repository": "git://github.com/image-size/image-size.git",
"author": "netroy <aditya@netroy.in> (http://netroy.in/)",
"license": "MIT",
"devDependencies": {
"@types/node": "12.7.8",
"@types/chai": "4.2.12",
"@types/glob": "7.1.3",
"@types/mocha": "8.0.3",
"@types/node": "14.6.3",
"@types/sinon": "9.0.5",
"@typescript-eslint/eslint-plugin": "4.0.1",
"@typescript-eslint/parser": "4.0.1",
"chai": "4.2.0",
"coveralls": "3.0.6",
"eslint": "6.5.0",
"glob": "7.1.4",
"mocha": "6.2.1",
"nyc": "14.1.1",
"sinon": "7.5.0",
"tslint": "5.20.0",
"typescript": "3.6.3"
"coveralls": "3.1.0",
"eslint": "7.8.1",
"glob": "7.1.6",
"mocha": "8.1.3",
"nyc": "15.1.0",
"sinon": "9.0.3",
"ts-node": "9.0.0",
"typedoc": "0.19.0",
"typescript": "4.0.2"
},

@@ -62,0 +70,0 @@ "dependencies": {

@@ -61,3 +61,3 @@ # image-size

### Using promises (node 8.x)
### Using promises (nodejs 10.x+)

@@ -133,2 +133,10 @@ ```javascript

## Hosted API
We also provide a hosted API for image-size which may simplify your use case.
<a href="https://image-size.saasify.sh">
<img src="https://badges.saasify.sh?text=View%20Hosted%20API" height="40"/>
</a>
## Credits

@@ -135,0 +143,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc