image-size
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
var typeMap = {}; | ||
@@ -2,0 +4,0 @@ var types = require('./types'); |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
var fs = require('fs'); | ||
@@ -16,6 +18,6 @@ var path = require('path'); | ||
// Maximum buffer size, with a default of 128 kilobytes. | ||
// TODO: make this adaptive based on the initial signature of the image | ||
// TO-DO: make this adaptive based on the initial signature of the image | ||
var bufferSize = 128*1024; | ||
function lookup (buffer, filepath) { | ||
function lookup (buffer, filepath, callback) { | ||
// detect the file type.. don't rely on the extension | ||
@@ -28,2 +30,5 @@ var type = detector(buffer, filepath); | ||
if (size !== false) { | ||
if (callback) { | ||
callback(null, size); | ||
} | ||
return size; | ||
@@ -33,4 +38,9 @@ } | ||
// throw up, if we can't understand the file | ||
throw new TypeError('unsupported file type'); | ||
// throw up, if we don't understand the file | ||
var err = new TypeError('unsupported file type'); | ||
if (callback) { | ||
callback(err); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
@@ -87,3 +97,3 @@ | ||
// return the dimensions | ||
callback(null, lookup(buffer, filepath)); | ||
lookup(buffer, filepath, callback); | ||
}); | ||
@@ -90,0 +100,0 @@ } else { |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
// Abstract reading multi-byte unsigned integers | ||
@@ -2,0 +4,0 @@ function readUInt (buffer, bits, offset, isBigEndian) { |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
module.exports = [ | ||
@@ -2,0 +4,0 @@ 'png', |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
function isBMP (buffer) { | ||
@@ -2,0 +4,0 @@ return ('BM' === buffer.toString('ascii', 0, 2)); |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
var gifRegexp = /^GIF8[7,9]a/; | ||
@@ -2,0 +4,0 @@ function isGIF (buffer) { |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
// NOTE: we only support baseline and progressive JPGs here | ||
@@ -6,3 +8,3 @@ // due to the structure of the loader class, we only get a buffer | ||
// TODO: handle the following as well | ||
// TO-DO: handle the following as well | ||
// ffe3 - Samsung D500 JPEG | ||
@@ -27,3 +29,3 @@ var validJFIFMarkers = { | ||
// TODO: validate the end-bytes of a jpeg file | ||
// TO-DO: validate the end-bytes of a jpeg file | ||
// use filepath, get the last bytes, check for ffd9 | ||
@@ -30,0 +32,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
var pngSignature = 'PNG\r\n\x1a\n'; | ||
@@ -2,0 +4,0 @@ function isPNG (buffer) { |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
function isPSD (buffer) { | ||
@@ -2,0 +4,0 @@ return ('8BPS' === buffer.toString('ascii', 0, 4)); |
@@ -0,3 +1,5 @@ | ||
'use strict'; | ||
// based on http://www.compix.com/fileformattif.htm | ||
// TODO: support big-endian as well | ||
// TO-DO: support big-endian as well | ||
@@ -4,0 +6,0 @@ var fs = require('fs'); |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
// based on https://developers.google.com/speed/webp/docs/riff_container | ||
@@ -39,3 +41,3 @@ | ||
// `& 0x3fff` returns the last 14 bits | ||
// TODO: include webp scaling in the calculations | ||
// TO-DO: include webp scaling in the calculations | ||
return { | ||
@@ -42,0 +44,0 @@ 'width': buffer.readInt16LE(6) & 0x3fff, |
{ | ||
"name": "image-size", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "get dimensions of any image file", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
17742
385