Updated the files.
This commit is contained in:
parent
1553e6b971
commit
753967d4f5
23418 changed files with 3784666 additions and 0 deletions
19
my-app/node_modules/image-size/lib/detector.js
generated
vendored
Executable file
19
my-app/node_modules/image-size/lib/detector.js
generated
vendored
Executable file
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
var typeMap = {};
|
||||
var types = require('./types');
|
||||
|
||||
// load all available handlers
|
||||
types.forEach(function (type) {
|
||||
typeMap[type] = require('./types/' + type).detect;
|
||||
});
|
||||
|
||||
module.exports = function (buffer, filepath) {
|
||||
var type, result;
|
||||
for (type in typeMap) {
|
||||
result = typeMap[type](buffer, filepath);
|
||||
if (result) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
};
|
105
my-app/node_modules/image-size/lib/index.js
generated
vendored
Executable file
105
my-app/node_modules/image-size/lib/index.js
generated
vendored
Executable file
|
@ -0,0 +1,105 @@
|
|||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var detector = require('./detector');
|
||||
|
||||
var handlers = {};
|
||||
var types = require('./types');
|
||||
|
||||
// load all available handlers
|
||||
types.forEach(function (type) {
|
||||
handlers[type] = require('./types/' + type);
|
||||
});
|
||||
|
||||
// Maximum buffer size, with a default of 128 kilobytes.
|
||||
// TO-DO: make this adaptive based on the initial signature of the image
|
||||
var MaxBufferSize = 128*1024;
|
||||
|
||||
function lookup (buffer, filepath) {
|
||||
// detect the file type.. don't rely on the extension
|
||||
var type = detector(buffer, filepath);
|
||||
|
||||
// find an appropriate handler for this file type
|
||||
if (type in handlers) {
|
||||
var size = handlers[type].calculate(buffer, filepath);
|
||||
if (size !== false) {
|
||||
size.type = type;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
// throw up, if we don't understand the file
|
||||
throw new TypeError('unsupported file type: ' + type + ' (file: ' + filepath + ')');
|
||||
}
|
||||
|
||||
function asyncFileToBuffer (filepath, callback) {
|
||||
// open the file in read only mode
|
||||
fs.open(filepath, 'r', function (err, descriptor) {
|
||||
if (err) { return callback(err); }
|
||||
var size = fs.fstatSync(descriptor).size;
|
||||
if (size <= 0){return callback(new Error("File size is not greater than 0 —— " + filepath)); }
|
||||
var bufferSize = Math.min(size, MaxBufferSize);
|
||||
var buffer = new Buffer(bufferSize);
|
||||
// read first buffer block from the file, asynchronously
|
||||
fs.read(descriptor, buffer, 0, bufferSize, 0, function (err) {
|
||||
if (err) { return callback(err); }
|
||||
// close the file, we are done
|
||||
fs.close(descriptor, function (err) {
|
||||
callback(err, buffer);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function syncFileToBuffer (filepath) {
|
||||
// read from the file, synchronously
|
||||
var descriptor = fs.openSync(filepath, 'r');
|
||||
var size = fs.fstatSync(descriptor).size;
|
||||
var bufferSize = Math.min(size, MaxBufferSize);
|
||||
var buffer = new Buffer(bufferSize);
|
||||
fs.readSync(descriptor, buffer, 0, bufferSize, 0);
|
||||
fs.closeSync(descriptor);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @params input - buffer or relative/absolute path of the image file
|
||||
* @params callback - optional function for async detection
|
||||
*/
|
||||
module.exports = function (input, callback) {
|
||||
|
||||
// Handle buffer input
|
||||
if (Buffer.isBuffer(input)) {
|
||||
return lookup(input);
|
||||
}
|
||||
|
||||
// input should be a string at this point
|
||||
if (typeof input !== 'string') {
|
||||
throw new TypeError('invalid invocation');
|
||||
}
|
||||
|
||||
// resolve the file path
|
||||
var filepath = path.resolve(input);
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
asyncFileToBuffer(filepath, function (err, buffer) {
|
||||
if (err) { return callback(err); }
|
||||
|
||||
// return the dimensions
|
||||
var dimensions;
|
||||
try {
|
||||
dimensions = lookup(buffer, filepath);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
callback(err, dimensions);
|
||||
});
|
||||
} else {
|
||||
var buffer = syncFileToBuffer(filepath);
|
||||
return lookup(buffer, filepath);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.types = types;
|
11
my-app/node_modules/image-size/lib/readUInt.js
generated
vendored
Executable file
11
my-app/node_modules/image-size/lib/readUInt.js
generated
vendored
Executable file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
// Abstract reading multi-byte unsigned integers
|
||||
function readUInt (buffer, bits, offset, isBigEndian) {
|
||||
offset = offset || 0;
|
||||
var endian = !!isBigEndian ? 'BE' : 'LE';
|
||||
var method = buffer['readUInt' + bits + endian];
|
||||
return method.call(buffer, offset);
|
||||
}
|
||||
|
||||
module.exports = readUInt;
|
13
my-app/node_modules/image-size/lib/types.js
generated
vendored
Executable file
13
my-app/node_modules/image-size/lib/types.js
generated
vendored
Executable file
|
@ -0,0 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = [
|
||||
'bmp',
|
||||
'gif',
|
||||
'jpg',
|
||||
'png',
|
||||
'psd',
|
||||
'svg',
|
||||
'tiff',
|
||||
'webp',
|
||||
'dds'
|
||||
];
|
17
my-app/node_modules/image-size/lib/types/bmp.js
generated
vendored
Executable file
17
my-app/node_modules/image-size/lib/types/bmp.js
generated
vendored
Executable file
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
function isBMP (buffer) {
|
||||
return ('BM' === buffer.toString('ascii', 0, 2));
|
||||
}
|
||||
|
||||
function calculate (buffer) {
|
||||
return {
|
||||
'width': buffer.readUInt32LE(18),
|
||||
'height': Math.abs(buffer.readInt32LE(22))
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'detect': isBMP,
|
||||
'calculate': calculate
|
||||
};
|
18
my-app/node_modules/image-size/lib/types/dds.js
generated
vendored
Executable file
18
my-app/node_modules/image-size/lib/types/dds.js
generated
vendored
Executable file
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
function isDDS(buffer){
|
||||
return buffer.readUInt32LE(0) === 0x20534444;
|
||||
}
|
||||
|
||||
function calculate(buffer){
|
||||
// read file resolution metadata
|
||||
return {
|
||||
'height': buffer.readUInt32LE(12),
|
||||
'width': buffer.readUInt32LE(16)
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'detect': isDDS,
|
||||
'calculate': calculate
|
||||
};
|
19
my-app/node_modules/image-size/lib/types/gif.js
generated
vendored
Executable file
19
my-app/node_modules/image-size/lib/types/gif.js
generated
vendored
Executable file
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
var gifRegexp = /^GIF8[79]a/;
|
||||
function isGIF (buffer) {
|
||||
var signature = buffer.toString('ascii', 0, 6);
|
||||
return (gifRegexp.test(signature));
|
||||
}
|
||||
|
||||
function calculate(buffer) {
|
||||
return {
|
||||
'width': buffer.readUInt16LE(6),
|
||||
'height': buffer.readUInt16LE(8)
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'detect': isGIF,
|
||||
'calculate': calculate
|
||||
};
|
62
my-app/node_modules/image-size/lib/types/jpg.js
generated
vendored
Executable file
62
my-app/node_modules/image-size/lib/types/jpg.js
generated
vendored
Executable file
|
@ -0,0 +1,62 @@
|
|||
'use strict';
|
||||
|
||||
// NOTE: we only support baseline and progressive JPGs here
|
||||
// due to the structure of the loader class, we only get a buffer
|
||||
// with a maximum size of 4096 bytes. so if the SOF marker is outside
|
||||
// if this range we can't detect the file size correctly.
|
||||
|
||||
function isJPG (buffer) { //, filepath
|
||||
var SOIMarker = buffer.toString('hex', 0, 2);
|
||||
return ('ffd8' === SOIMarker);
|
||||
}
|
||||
|
||||
function extractSize (buffer, i) {
|
||||
return {
|
||||
'height' : buffer.readUInt16BE(i),
|
||||
'width' : buffer.readUInt16BE(i + 2)
|
||||
};
|
||||
}
|
||||
|
||||
function validateBuffer (buffer, i) {
|
||||
// index should be within buffer limits
|
||||
if (i > buffer.length) {
|
||||
throw new TypeError('Corrupt JPG, exceeded buffer limits');
|
||||
}
|
||||
// Every JPEG block must begin with a 0xFF
|
||||
if (buffer[i] !== 0xFF) {
|
||||
throw new TypeError('Invalid JPG, marker table corrupted');
|
||||
}
|
||||
}
|
||||
|
||||
function calculate (buffer) {
|
||||
|
||||
// Skip 4 chars, they are for signature
|
||||
buffer = buffer.slice(4);
|
||||
|
||||
var i, next;
|
||||
while (buffer.length) {
|
||||
// read length of the next block
|
||||
i = buffer.readUInt16BE(0);
|
||||
|
||||
// ensure correct format
|
||||
validateBuffer(buffer, i);
|
||||
|
||||
// 0xFFC0 is baseline standard(SOF)
|
||||
// 0xFFC1 is baseline optimized(SOF)
|
||||
// 0xFFC2 is progressive(SOF2)
|
||||
next = buffer[i + 1];
|
||||
if (next === 0xC0 || next === 0xC1 || next === 0xC2) {
|
||||
return extractSize(buffer, i + 5);
|
||||
}
|
||||
|
||||
// move to the next block
|
||||
buffer = buffer.slice(i + 2);
|
||||
}
|
||||
|
||||
throw new TypeError('Invalid JPG, no size found');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'detect': isJPG,
|
||||
'calculate': calculate
|
||||
};
|
36
my-app/node_modules/image-size/lib/types/png.js
generated
vendored
Executable file
36
my-app/node_modules/image-size/lib/types/png.js
generated
vendored
Executable file
|
@ -0,0 +1,36 @@
|
|||
'use strict';
|
||||
|
||||
var pngSignature = 'PNG\r\n\x1a\n';
|
||||
var pngImageHeaderChunkName = 'IHDR';
|
||||
var pngFriedChunkName = 'CgBI'; // Used to detect "fried" png's: http://www.jongware.com/pngdefry.html
|
||||
|
||||
function isPNG (buffer) {
|
||||
if (pngSignature === buffer.toString('ascii', 1, 8)) {
|
||||
var chunkName = buffer.toString('ascii', 12, 16);
|
||||
if (chunkName === pngFriedChunkName) {
|
||||
chunkName = buffer.toString('ascii', 28, 32);
|
||||
}
|
||||
if (chunkName !== pngImageHeaderChunkName) {
|
||||
throw new TypeError('invalid png');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function calculate (buffer) {
|
||||
if (buffer.toString('ascii', 12, 16) === pngFriedChunkName) {
|
||||
return {
|
||||
'width': buffer.readUInt32BE(32),
|
||||
'height': buffer.readUInt32BE(36)
|
||||
};
|
||||
}
|
||||
return {
|
||||
'width': buffer.readUInt32BE(16),
|
||||
'height': buffer.readUInt32BE(20)
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'detect': isPNG,
|
||||
'calculate': calculate
|
||||
};
|
17
my-app/node_modules/image-size/lib/types/psd.js
generated
vendored
Executable file
17
my-app/node_modules/image-size/lib/types/psd.js
generated
vendored
Executable file
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
function isPSD (buffer) {
|
||||
return ('8BPS' === buffer.toString('ascii', 0, 4));
|
||||
}
|
||||
|
||||
function calculate (buffer) {
|
||||
return {
|
||||
'width': buffer.readUInt32BE(18),
|
||||
'height': buffer.readUInt32BE(14)
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'detect': isPSD,
|
||||
'calculate': calculate
|
||||
};
|
78
my-app/node_modules/image-size/lib/types/svg.js
generated
vendored
Executable file
78
my-app/node_modules/image-size/lib/types/svg.js
generated
vendored
Executable file
|
@ -0,0 +1,78 @@
|
|||
'use strict';
|
||||
|
||||
var svgReg = /<svg[^>]+[^>]*>/;
|
||||
function isSVG (buffer) {
|
||||
return svgReg.test(buffer);
|
||||
}
|
||||
|
||||
var extractorRegExps = {
|
||||
'root': /<svg\s[^>]+>/,
|
||||
'width': /\bwidth=(['"])([^%]+?)\1/,
|
||||
'height': /\bheight=(['"])([^%]+?)\1/,
|
||||
'viewbox': /\bviewBox=(['"])(.+?)\1/
|
||||
};
|
||||
|
||||
function parseViewbox (viewbox) {
|
||||
var bounds = viewbox.split(' ');
|
||||
return {
|
||||
'width': parseInt(bounds[2], 10),
|
||||
'height': parseInt(bounds[3], 10)
|
||||
};
|
||||
}
|
||||
|
||||
function parseAttributes (root) {
|
||||
var width = root.match(extractorRegExps.width);
|
||||
var height = root.match(extractorRegExps.height);
|
||||
var viewbox = root.match(extractorRegExps.viewbox);
|
||||
return {
|
||||
'width': width && parseInt(width[2], 10),
|
||||
'height': height && parseInt(height[2], 10),
|
||||
'viewbox': viewbox && parseViewbox(viewbox[2])
|
||||
};
|
||||
}
|
||||
|
||||
function calculateByDimensions (attrs) {
|
||||
return {
|
||||
'width': attrs.width,
|
||||
'height': attrs.height
|
||||
};
|
||||
}
|
||||
|
||||
function calculateByViewbox (attrs) {
|
||||
var ratio = attrs.viewbox.width / attrs.viewbox.height;
|
||||
if (attrs.width) {
|
||||
return {
|
||||
'width': attrs.width,
|
||||
'height': Math.floor(attrs.width / ratio)
|
||||
};
|
||||
}
|
||||
if (attrs.height) {
|
||||
return {
|
||||
'width': Math.floor(attrs.height * ratio),
|
||||
'height': attrs.height
|
||||
};
|
||||
}
|
||||
return {
|
||||
'width': attrs.viewbox.width,
|
||||
'height': attrs.viewbox.height
|
||||
};
|
||||
}
|
||||
|
||||
function calculate (buffer) {
|
||||
var root = buffer.toString('utf8').match(extractorRegExps.root);
|
||||
if (root) {
|
||||
var attrs = parseAttributes(root[0]);
|
||||
if (attrs.width && attrs.height) {
|
||||
return calculateByDimensions(attrs);
|
||||
}
|
||||
if (attrs.viewbox) {
|
||||
return calculateByViewbox(attrs);
|
||||
}
|
||||
}
|
||||
throw new TypeError('invalid svg');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'detect': isSVG,
|
||||
'calculate': calculate
|
||||
};
|
118
my-app/node_modules/image-size/lib/types/tiff.js
generated
vendored
Executable file
118
my-app/node_modules/image-size/lib/types/tiff.js
generated
vendored
Executable file
|
@ -0,0 +1,118 @@
|
|||
'use strict';
|
||||
|
||||
// based on http://www.compix.com/fileformattif.htm
|
||||
// TO-DO: support big-endian as well
|
||||
|
||||
var fs = require('fs');
|
||||
var readUInt = require('../readUInt');
|
||||
|
||||
function isTIFF (buffer) {
|
||||
var hex4 = buffer.toString('hex', 0, 4);
|
||||
return ('49492a00' === hex4 || '4d4d002a' === hex4);
|
||||
}
|
||||
|
||||
// Read IFD (image-file-directory) into a buffer
|
||||
function readIFD (buffer, filepath, isBigEndian) {
|
||||
|
||||
var ifdOffset = readUInt(buffer, 32, 4, isBigEndian);
|
||||
|
||||
// read only till the end of the file
|
||||
var bufferSize = 1024;
|
||||
var fileSize = fs.statSync(filepath).size;
|
||||
if (ifdOffset + bufferSize > fileSize) {
|
||||
bufferSize = fileSize - ifdOffset - 10;
|
||||
}
|
||||
|
||||
// populate the buffer
|
||||
var endBuffer = new Buffer(bufferSize);
|
||||
var descriptor = fs.openSync(filepath, 'r');
|
||||
fs.readSync(descriptor, endBuffer, 0, bufferSize, ifdOffset);
|
||||
|
||||
// var ifdLength = readUInt(endBuffer, 16, 0, isBigEndian);
|
||||
var ifdBuffer = endBuffer.slice(2); //, 2 + 12 * ifdLength);
|
||||
return ifdBuffer;
|
||||
}
|
||||
|
||||
// TIFF values seem to be messed up on Big-Endian, this helps
|
||||
function readValue (buffer, isBigEndian) {
|
||||
var low = readUInt(buffer, 16, 8, isBigEndian);
|
||||
var high = readUInt(buffer, 16, 10, isBigEndian);
|
||||
return (high << 16) + low;
|
||||
}
|
||||
|
||||
// move to the next tag
|
||||
function nextTag (buffer) {
|
||||
if (buffer.length > 24) {
|
||||
return buffer.slice(12);
|
||||
}
|
||||
}
|
||||
|
||||
// Extract IFD tags from TIFF metadata
|
||||
function extractTags (buffer, isBigEndian) {
|
||||
var tags = {};
|
||||
var code, type, length;
|
||||
|
||||
while (buffer && buffer.length) {
|
||||
code = readUInt(buffer, 16, 0, isBigEndian);
|
||||
type = readUInt(buffer, 16, 2, isBigEndian);
|
||||
length = readUInt(buffer, 32, 4, isBigEndian);
|
||||
|
||||
// 0 means end of IFD
|
||||
if (code === 0) {
|
||||
break;
|
||||
} else {
|
||||
// 256 is width, 257 is height
|
||||
// if (code === 256 || code === 257) {
|
||||
if (length === 1 && (type === 3 || type === 4)) {
|
||||
tags[code] = readValue(buffer, isBigEndian);
|
||||
}
|
||||
|
||||
// move to the next tag
|
||||
buffer = nextTag(buffer);
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
// Test if the TIFF is Big Endian or Little Endian
|
||||
function determineEndianness (buffer) {
|
||||
var signature = buffer.toString('ascii', 0, 2);
|
||||
if ('II' === signature) {
|
||||
return 'LE';
|
||||
} else if ('MM' === signature) {
|
||||
return 'BE';
|
||||
}
|
||||
}
|
||||
|
||||
function calculate (buffer, filepath) {
|
||||
|
||||
if (!filepath) {
|
||||
throw new TypeError('Tiff doesn\'t support buffer');
|
||||
}
|
||||
|
||||
// Determine BE/LE
|
||||
var isBigEndian = determineEndianness(buffer) === 'BE';
|
||||
|
||||
// read the IFD
|
||||
var ifdBuffer = readIFD(buffer, filepath, isBigEndian);
|
||||
|
||||
// extract the tags from the IFD
|
||||
var tags = extractTags(ifdBuffer, isBigEndian);
|
||||
|
||||
var width = tags[256];
|
||||
var height = tags[257];
|
||||
|
||||
if (!width || !height) {
|
||||
throw new TypeError('Invalid Tiff, missing tags');
|
||||
}
|
||||
|
||||
return {
|
||||
'width': width,
|
||||
'height': height
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'detect': isTIFF,
|
||||
'calculate': calculate
|
||||
};
|
69
my-app/node_modules/image-size/lib/types/webp.js
generated
vendored
Executable file
69
my-app/node_modules/image-size/lib/types/webp.js
generated
vendored
Executable file
|
@ -0,0 +1,69 @@
|
|||
'use strict';
|
||||
|
||||
// based on https://developers.google.com/speed/webp/docs/riff_container
|
||||
|
||||
function isWebP (buffer) {
|
||||
var riffHeader = 'RIFF' === buffer.toString('ascii', 0, 4);
|
||||
var webpHeader = 'WEBP' === buffer.toString('ascii', 8, 12);
|
||||
var vp8Header = 'VP8' === buffer.toString('ascii', 12, 15);
|
||||
return (riffHeader && webpHeader && vp8Header);
|
||||
}
|
||||
|
||||
function calculate (buffer) {
|
||||
var chunkHeader = buffer.toString('ascii', 12, 16);
|
||||
buffer = buffer.slice(20, 30);
|
||||
|
||||
// Extended webp stream signature
|
||||
if (chunkHeader === 'VP8X') {
|
||||
var extendedHeader = buffer[0];
|
||||
var validStart = (extendedHeader & 0xc0) === 0;
|
||||
var validEnd = (extendedHeader & 0x01) === 0;
|
||||
if (validStart && validEnd) {
|
||||
return calculateExtended(buffer);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Lossless webp stream signature
|
||||
if (chunkHeader === 'VP8 ' && buffer[0] !== 0x2f) {
|
||||
return calculateLossy(buffer);
|
||||
}
|
||||
|
||||
// Lossy webp stream signature
|
||||
var signature = buffer.toString('hex', 3, 6);
|
||||
if (chunkHeader === 'VP8L' && signature !== '9d012a') {
|
||||
return calculateLossless(buffer);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function calculateExtended (buffer) {
|
||||
return {
|
||||
'width': 1 + buffer.readUIntLE(4, 3),
|
||||
'height': 1 + buffer.readUIntLE(7, 3)
|
||||
}
|
||||
}
|
||||
|
||||
function calculateLossless (buffer) {
|
||||
return {
|
||||
'width': 1 + (((buffer[2] & 0x3F) << 8) | buffer[1]),
|
||||
'height': 1 + (((buffer[4] & 0xF) << 10) | (buffer[3] << 2) |
|
||||
((buffer[2] & 0xC0) >> 6))
|
||||
};
|
||||
}
|
||||
|
||||
function calculateLossy (buffer) {
|
||||
// `& 0x3fff` returns the last 14 bits
|
||||
// TO-DO: include webp scaling in the calculations
|
||||
return {
|
||||
'width': buffer.readInt16LE(6) & 0x3fff,
|
||||
'height': buffer.readInt16LE(8) & 0x3fff
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'detect': isWebP,
|
||||
'calculate': calculate
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue