image-size
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -36,3 +36,3 @@ "use strict"; | ||
// detect the file type.. don't rely on the extension | ||
const type = detector_1.detector(buffer); | ||
const type = (0, detector_1.detector)(buffer); | ||
if (typeof type !== 'undefined') { | ||
@@ -62,12 +62,15 @@ if (globalOptions.disabledTypes.indexOf(type) > -1) { | ||
const handle = yield fs.promises.open(filepath, 'r'); | ||
const { size } = yield handle.stat(); | ||
if (size <= 0) { | ||
try { | ||
const { size } = yield handle.stat(); | ||
if (size <= 0) { | ||
throw new Error('Empty file'); | ||
} | ||
const bufferSize = Math.min(size, MaxBufferSize); | ||
const buffer = Buffer.alloc(bufferSize); | ||
yield handle.read(buffer, 0, bufferSize, 0); | ||
return buffer; | ||
} | ||
finally { | ||
yield handle.close(); | ||
throw new Error('Empty file'); | ||
} | ||
const bufferSize = Math.min(size, MaxBufferSize); | ||
const buffer = Buffer.alloc(bufferSize); | ||
yield handle.read(buffer, 0, bufferSize, 0); | ||
yield handle.close(); | ||
return buffer; | ||
}); | ||
@@ -84,12 +87,15 @@ } | ||
const descriptor = fs.openSync(filepath, 'r'); | ||
const { size } = fs.fstatSync(descriptor); | ||
if (size <= 0) { | ||
try { | ||
const { size } = fs.fstatSync(descriptor); | ||
if (size <= 0) { | ||
throw new Error('Empty file'); | ||
} | ||
const bufferSize = Math.min(size, MaxBufferSize); | ||
const buffer = Buffer.alloc(bufferSize); | ||
fs.readSync(descriptor, buffer, 0, bufferSize, 0); | ||
return buffer; | ||
} | ||
finally { | ||
fs.closeSync(descriptor); | ||
throw new Error('Empty file'); | ||
} | ||
const bufferSize = Math.min(size, MaxBufferSize); | ||
const buffer = Buffer.alloc(bufferSize); | ||
fs.readSync(descriptor, buffer, 0, bufferSize, 0); | ||
fs.closeSync(descriptor); | ||
return buffer; | ||
} | ||
@@ -96,0 +102,0 @@ // eslint-disable-next-line @typescript-eslint/no-use-before-define |
@@ -36,3 +36,3 @@ "use strict"; | ||
const offset = EXIF_HEADER_BYTES + idfOffset; | ||
const idfDirectoryEntries = readUInt_1.readUInt(exifBlock, 16, offset, isBigEndian); | ||
const idfDirectoryEntries = (0, readUInt_1.readUInt)(exifBlock, 16, offset, isBigEndian); | ||
for (let directoryEntryNumber = 0; directoryEntryNumber < idfDirectoryEntries; directoryEntryNumber++) { | ||
@@ -46,6 +46,6 @@ const start = offset + NUM_DIRECTORY_ENTRIES_BYTES + (directoryEntryNumber * IDF_ENTRY_BYTES); | ||
const block = exifBlock.slice(start, end); | ||
const tagNumber = readUInt_1.readUInt(block, 16, 0, isBigEndian); | ||
const tagNumber = (0, readUInt_1.readUInt)(block, 16, 0, isBigEndian); | ||
// 0x0112 (decimal: 274) is the `orientation` tag ID | ||
if (tagNumber === 274) { | ||
const dataFormat = readUInt_1.readUInt(block, 16, 2, isBigEndian); | ||
const dataFormat = (0, readUInt_1.readUInt)(block, 16, 2, isBigEndian); | ||
if (dataFormat !== 3) { | ||
@@ -56,7 +56,7 @@ return; | ||
// if there would more than 4 bytes in total it's a pointer | ||
const numberOfComponents = readUInt_1.readUInt(block, 32, 4, isBigEndian); | ||
const numberOfComponents = (0, readUInt_1.readUInt)(block, 32, 4, isBigEndian); | ||
if (numberOfComponents !== 1) { | ||
return; | ||
} | ||
return readUInt_1.readUInt(block, 16, 8, isBigEndian); | ||
return (0, readUInt_1.readUInt)(block, 16, 8, isBigEndian); | ||
} | ||
@@ -63,0 +63,0 @@ } |
@@ -10,3 +10,3 @@ "use strict"; | ||
function readIFD(buffer, filepath, isBigEndian) { | ||
const ifdOffset = readUInt_1.readUInt(buffer, 32, 4, isBigEndian); | ||
const ifdOffset = (0, readUInt_1.readUInt)(buffer, 32, 4, isBigEndian); | ||
// read only till the end of the file | ||
@@ -27,4 +27,4 @@ let bufferSize = 1024; | ||
function readValue(buffer, isBigEndian) { | ||
const low = readUInt_1.readUInt(buffer, 16, 8, isBigEndian); | ||
const high = readUInt_1.readUInt(buffer, 16, 10, isBigEndian); | ||
const low = (0, readUInt_1.readUInt)(buffer, 16, 8, isBigEndian); | ||
const high = (0, readUInt_1.readUInt)(buffer, 16, 10, isBigEndian); | ||
return (high << 16) + low; | ||
@@ -43,5 +43,5 @@ } | ||
while (temp && temp.length) { | ||
const code = readUInt_1.readUInt(temp, 16, 0, isBigEndian); | ||
const type = readUInt_1.readUInt(temp, 16, 2, isBigEndian); | ||
const length = readUInt_1.readUInt(temp, 32, 4, isBigEndian); | ||
const code = (0, readUInt_1.readUInt)(temp, 16, 0, isBigEndian); | ||
const type = (0, readUInt_1.readUInt)(temp, 16, 2, isBigEndian); | ||
const length = (0, readUInt_1.readUInt)(temp, 32, 4, isBigEndian); | ||
// 0 means end of IFD | ||
@@ -48,0 +48,0 @@ if (code === 0) { |
{ | ||
"name": "image-size", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "get dimensions of any image file", | ||
@@ -14,5 +14,3 @@ "main": "dist/index.js", | ||
}, | ||
"bin": { | ||
"image-size": "bin/image-size.js" | ||
}, | ||
"bin": "bin/image-size.js", | ||
"scripts": { | ||
@@ -49,22 +47,23 @@ "pretest": "eslint --ext .ts,.js bin lib specs", | ||
"devDependencies": { | ||
"@types/chai": "4.2.16", | ||
"@types/glob": "7.1.3", | ||
"@types/mocha": "8.2.2", | ||
"@types/node": "14.14.37", | ||
"@types/sinon": "10.0.0", | ||
"@typescript-eslint/eslint-plugin": "4.22.0", | ||
"@typescript-eslint/parser": "4.22.0", | ||
"@types/chai": "4.3.0", | ||
"@types/glob": "7.2.0", | ||
"@types/mocha": "9.0.0", | ||
"@types/node": "17.0.8", | ||
"@types/sinon": "10.0.6", | ||
"@typescript-eslint/eslint-plugin": "5.9.1", | ||
"@typescript-eslint/parser": "5.9.1", | ||
"chai": "4.3.4", | ||
"eslint": "7.24.0", | ||
"glob": "7.1.6", | ||
"mocha": "8.3.2", | ||
"eslint": "8.6.0", | ||
"glob": "7.2.0", | ||
"mocha": "9.1.3", | ||
"nyc": "15.1.0", | ||
"sinon": "10.0.0", | ||
"ts-node": "9.1.1", | ||
"typedoc": "0.20.35", | ||
"typescript": "4.2.4" | ||
"sinon": "12.0.1", | ||
"ts-node": "10.4.0", | ||
"typedoc": "0.22.10", | ||
"typescript": "4.5.4" | ||
}, | ||
"dependencies": { | ||
"queue": "6.0.2" | ||
} | ||
}, | ||
"packageManager": "yarn@3.1.1" | ||
} |
@@ -141,2 +141,12 @@ # image-size | ||
### 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) | ||
@@ -143,0 +153,0 @@ |
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
45406
1150
183
3