image-size
Advanced tools
Comparing version 0.7.3 to 0.7.4
@@ -31,2 +31,3 @@ 'use strict'; | ||
var BIG_ENDIAN_BYTE_ALIGN = '4d4d'; | ||
var LITTLE_ENDIAN_BYTE_ALIGN = '4949'; | ||
@@ -37,3 +38,3 @@ // Each entry is exactly 12 bytes | ||
function extractOrientation (buffer, i) { | ||
function validateExifBlock (buffer, i) { | ||
// Skip APP1 Data Size | ||
@@ -44,4 +45,13 @@ var exifBlock = buffer.slice(APP1_DATA_SIZE_BYTES, i); | ||
var byteAlign = exifBlock.toString('hex', EXIF_HEADER_BYTES, EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES); | ||
var bigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN; | ||
// Ignore Empty EXIF. Validate byte alignment | ||
var isBigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN; | ||
var isLittleEndian = byteAlign === LITTLE_ENDIAN_BYTE_ALIGN; | ||
if (isBigEndian || isLittleEndian) { | ||
return extractOrientation(exifBlock, isBigEndian); | ||
} | ||
} | ||
function extractOrientation (exifBlock, isBigEndian) { | ||
// TODO: assert that this contains 0x002A | ||
@@ -58,3 +68,3 @@ // var STATIC_MOTOROLA_TIFF_HEADER_BYTES = 2; | ||
var idfDirectoryEntries = readUInt(exifBlock, 16, offset, bigEndian); | ||
var idfDirectoryEntries = readUInt(exifBlock, 16, offset, isBigEndian); | ||
@@ -68,7 +78,7 @@ var start; | ||
var block = exifBlock.slice(start, end); | ||
var tagNumber = readUInt(block, 16, 0, bigEndian); | ||
var tagNumber = readUInt(block, 16, 0, isBigEndian); | ||
// 0x0112 (decimal: 274) is the `orientation` tag ID | ||
if (tagNumber === 274) { | ||
var dataFormat = readUInt(block, 16, 2, bigEndian); | ||
var dataFormat = readUInt(block, 16, 2, isBigEndian); | ||
if (dataFormat !== 3) { | ||
@@ -80,3 +90,3 @@ return; | ||
// if there would more than 4 bytes in total it's a pointer | ||
var numberOfComponents = readUInt(block, 32, 4, bigEndian); | ||
var numberOfComponents = readUInt(block, 32, 4, isBigEndian); | ||
if (numberOfComponents !== 1) { | ||
@@ -86,5 +96,3 @@ return; | ||
var orientation = readUInt(block, 16, 8, bigEndian); | ||
return orientation; | ||
return readUInt(block, 16, 8, isBigEndian); | ||
} | ||
@@ -116,5 +124,4 @@ } | ||
if (isEXIF(buffer)) { | ||
orientation = extractOrientation(buffer, i); | ||
orientation = validateExifBlock(buffer, i); | ||
} | ||
@@ -121,0 +128,0 @@ |
{ | ||
"name": "image-size", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "get dimensions of any image file", | ||
@@ -48,6 +48,6 @@ "main": "lib/index.js", | ||
"glob": "7.1.3", | ||
"mocha": "6.0.2", | ||
"nyc": "13.3.0", | ||
"sinon": "7.3.1" | ||
"mocha": "6.1.4", | ||
"nyc": "14.0.0", | ||
"sinon": "7.3.2" | ||
} | ||
} |
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
30422
835