08-27-周三_17-09-29

This commit is contained in:
2025-08-27 17:10:05 +08:00
commit 86df397d8f
12735 changed files with 1145479 additions and 0 deletions

11
node_modules/image-size/.npmignore generated vendored Normal file
View File

@@ -0,0 +1,11 @@
.coveralls.yml
.jshintrc
.travis.yml
coverage.html
Makefile
lib-cov/
specs/
coverage/
*.jpg
*.png

9
node_modules/image-size/Contributors.md generated vendored Normal file
View File

@@ -0,0 +1,9 @@
##### Contributors
* [Aditya Yadav](https://github.com/netroy)
* [Adam Renklint](https://github.com/adamrenklint) (6Wunderkinder GmbH)
* [Manfred Manik Nerurkar](https://github.com/Manny-MADE) (copyright owned by MADE, GmbH)
* [Rudy Krol](https://github.com/rkrol)
* [Linus Unnebäck](https://github.com/LinusU)
* [Ross Johnson](https://github.com/rossj) (Mazira, LLC)
* [Shinnosuke Watanabe](https://github.com/shinnn)

9
node_modules/image-size/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright © 2014 Aditya Yadav, http://netroy.in
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

70
node_modules/image-size/Readme.md generated vendored Normal file
View File

@@ -0,0 +1,70 @@
[![Build Status](https://travis-ci.org/netroy/image-size.png?branch=master)](https://travis-ci.org/netroy/image-size)
[![NPM Downloads](http://img.shields.io/npm/dm/image-size.svg)](https://npmjs.org/package/image-size)
[![Gittip](http://img.shields.io/gittip/netroy.svg)](https://www.gittip.com/netroy/)
[![Coverage Status](https://coveralls.io/repos/netroy/image-size/badge.png?branch=master)](https://coveralls.io/r/netroy/image-size?branch=master)
[![Technical debt analysis](https://www.sidekickjs.com/r/netroy/image-size/status_badge.svg)](https://www.sidekickjs.com/r/netroy/image-size)
[![Code Climate](https://codeclimate.com/github/netroy/image-size.png)](https://codeclimate.com/github/netroy/image-size)
[![Dependency Status](https://gemnasium.com/netroy/image-size.png)](https://gemnasium.com/netroy/image-size)
#### Instalation
`npm install image-size`
#### Usage
```javascript
var sizeOf = require('image-size');
var dimensions = sizeOf('images/funny-cats.png');
console.log(dimensions.width, dimensions.height);
```
##### Async version
```javascript
var sizeOf = require('image-size');
sizeOf('images/funny-cats.png', function (err, dimensions) {
console.log(dimensions.width, dimensions.height);
});
```
##### Using a url
```javascript
var url = require('url');
var http = require('http');
var sizeOf = require('image-size');
var imgUrl = 'http://my-amazing-website.com/image.jpeg';
var options = url.parse(imgUrl);
http.get(options, function (response) {
var chunks = [];
response.on('data', function (chunk) {
chunks.push(chunk);
}).on('end', function() {
var buffer = Buffer.concat(chunks);
console.log(sizeOf(buffer));
});
});
```
You can optionally check the buffer lengths & stop downloading the image after a few kilobytes.
**You don't need to download the entire image**
#### Supported formats
* BMP
* GIF
* JPEG
* PNG
* PSD
* TIFF
* WebP
* SVG
##### Upcoming
* SWF
##### Credits
not a direct port, but an attempt to have something like
[dabble's imagesize](https://github.com/dabble/imagesize/blob/master/lib/image_size.rb) as a node module.
##### [Contributors](Contributors.md)

35
node_modules/image-size/bin/image-size generated vendored Normal file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var imageSize = require('..');
var files = process.argv.slice(2);
if (!files.length) {
console.error('Usage: image-size image1 [image2] [image3] ...');
process.exit(-1);
}
var red = ['\x1B[31m', '\x1B[39m'];
// var bold = ['\x1B[1m', '\x1B[22m'];
var grey = ['\x1B[90m', '\x1B[39m'];
var green = ['\x1B[32m', '\x1B[39m'];
files.forEach(function (image) {
try {
if (fs.existsSync(path.resolve(image))) {
var size = imageSize(image);
var label = green[0] + size.width + green[1] +
grey[0] + 'x' + grey[1] +
green[0] + size.height + green[1];
console.info(label, '-', grey[0] + image + grey[1]);
} else {
console.error('file doesn\'t exist - ', image);
}
} catch (e) {
// console.error(e.stack);
console.error(red[0] + e.message + red[1], '-', image);
}
});

19
node_modules/image-size/lib/detector.js generated vendored Normal file
View 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;
}
}
};

103
node_modules/image-size/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,103 @@
'use strict';
var fs = require('fs');
var path = require('path');
var libpath = process.env.TEST_COV ? '../lib-cov/' : '../lib/';
var detector = require(libpath + 'detector');
var handlers = {};
var types = require(libpath + 'types');
// load all available handlers
types.forEach(function (type) {
handlers[type] = require(libpath + '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');
}
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;
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 (input instanceof Buffer) {
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);
}
};

11
node_modules/image-size/lib/readUInt.js generated vendored Normal file
View 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;

12
node_modules/image-size/lib/types.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
'use strict';
module.exports = [
'bmp',
'gif',
'jpg',
'png',
'psd',
'svg',
'tiff',
'webp'
];

17
node_modules/image-size/lib/types/bmp.js generated vendored Normal file
View 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': buffer.readUInt32LE(22)
};
}
module.exports = {
'detect': isBMP,
'calculate': calculate
};

19
node_modules/image-size/lib/types/gif.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
'use strict';
var gifRegexp = /^GIF8[7,9]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
};

96
node_modules/image-size/lib/types/jpg.js generated vendored Normal file
View File

@@ -0,0 +1,96 @@
'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.
// TO-DO: handle all JFIFs
var validJFIFMarkers = {
'ffdb': '0001010101', // Samsung D807 JPEG
'ffe0': '4a46494600', // Standard JPEG
'ffe1': '4578696600', // Camera JPEG, with EXIF data
'ffe2': '4943435f50', // Canon EOS-1D JPEG
'ffe3': '', // Samsung D500 JPEG
'ffe8': '5350494646', // SPIFF JPEG
'ffec': '4475636b79', // Photoshop JPEG
'ffed': '50686f746f', // Adobe JPEG, Photoshop CMYK buffer
'ffee': '41646f6265' // Adobe JPEG, Unrecognised (Lightroom??)
};
var red = ['\x1B[31m', '\x1B[39m'];
function isJPG (buffer) { //, filepath
var SOIMarker = buffer.toString('hex', 0, 2);
var JFIFMarker = buffer.toString('hex', 2, 4);
// not a valid jpeg
if ('ffd8' !== SOIMarker) {
return false;
}
// TO-DO: validate the end-bytes of a jpeg file
// use filepath, get the last bytes, check for ffd9
var got = buffer.toString('hex', 6, 11);
var expected = JFIFMarker && validJFIFMarkers[JFIFMarker];
if (expected === '') {
console.warn(
red[0] +
'this looks like a unrecognised jpeg\n' +
'please report the issue here\n' +
red[1],
'\thttps://github.com/netroy/image-size/issues/new\n'
);
return false;
}
return (got === expected) || (JFIFMarker === 'ffdb');
}
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 5 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(SOF)
// 0xFFC2 is progressive(SOF2)
next = buffer[i + 1];
if (next === 0xC0 || 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
};

23
node_modules/image-size/lib/types/png.js generated vendored Normal file
View File

@@ -0,0 +1,23 @@
'use strict';
var pngSignature = 'PNG\r\n\x1a\n';
function isPNG (buffer) {
if (pngSignature === buffer.toString('ascii', 1, 8)) {
if ('IHDR' !== buffer.toString('ascii', 12, 16)) {
throw new TypeError('invalid png');
}
return true;
}
}
function calculate (buffer) {
return {
'width': buffer.readUInt32BE(16),
'height': buffer.readUInt32BE(20)
};
}
module.exports = {
'detect': isPNG,
'calculate': calculate
};

17
node_modules/image-size/lib/types/psd.js generated vendored Normal file
View 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
};

69
node_modules/image-size/lib/types/svg.js generated vendored Normal file
View File

@@ -0,0 +1,69 @@
'use strict';
var svgReg = /<svg[^>]+[^>]*>/;
function isSVG (buffer) {
return svgReg.test(buffer);
}
var extractorRegExps = {
'root': /<svg [^>]+>/,
'width': /(^|\s)width\s*=\s*"(.+?)"/i,
'height': /(^|\s)height\s*=\s*"(.+?)"/i,
'viewbox': /(^|\s)viewbox\s*=\s*"(.+?)"/i
};
function getRatio (viewbox) {
var ratio = 1;
if (viewbox && viewbox[2]) {
var dim = viewbox[2].split(/\s/g);
if (dim.length === 4) {
dim = dim.map(function (i) {
return parseInt(i, 10);
});
ratio = (dim[2] - dim[0]) / (dim[3] - dim[1]);
}
}
return ratio;
}
function parse (buffer) {
var body = buffer.toString().replace(/[\r\n\s]+/g, ' ');
var section = body.match(extractorRegExps.root);
var root = section && section[0];
if (root) {
var width = root.match(extractorRegExps.width);
var height = root.match(extractorRegExps.height);
var viewbox = root.match(extractorRegExps.viewbox);
var ratio = getRatio(viewbox);
return {
'width': parseInt(width && width[2], 10) || 0,
'height': parseInt(height && height[2], 10) || 0,
'ratio': ratio
};
}
}
function calculate (buffer) {
var parsed = parse(buffer);
var width = parsed.width;
var height = parsed.height;
var ratio = parsed.ratio;
if (width && height) {
return { 'width': width, 'height': height };
} else {
if (width) {
return { 'width': width, 'height': Math.floor(width / ratio) };
} else if (height) {
return { 'width': Math.floor(height * ratio), 'height': height };
} else {
throw new TypeError('invalid svg');
}
}
}
module.exports = {
'detect': isSVG,
'calculate': calculate
};

118
node_modules/image-size/lib/types/tiff.js generated vendored Normal file
View 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) {
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
};

51
node_modules/image-size/lib/types/webp.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
'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);
// 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 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
};

108
node_modules/image-size/package.json generated vendored Normal file
View File

@@ -0,0 +1,108 @@
{
"_args": [
[
{
"name": "image-size",
"raw": "image-size@~0.3.5",
"rawSpec": "~0.3.5",
"scope": null,
"spec": ">=0.3.5 <0.4.0",
"type": "range"
},
"F:\\tmp\\gitbook\\node_modules\\less"
]
],
"_from": "image-size@>=0.3.5 <0.4.0",
"_id": "image-size@0.3.5",
"_inCache": true,
"_installable": true,
"_location": "/image-size",
"_npmUser": {
"email": "aditya@netroy.in",
"name": "netroy"
},
"_npmVersion": "2.0.0",
"_phantomChildren": {},
"_requested": {
"name": "image-size",
"raw": "image-size@~0.3.5",
"rawSpec": "~0.3.5",
"scope": null,
"spec": ">=0.3.5 <0.4.0",
"type": "range"
},
"_requiredBy": [
"/less"
],
"_resolved": "https://registry.npmjs.org/image-size/-/image-size-0.3.5.tgz",
"_shasum": "83240eab2fb5b00b04aab8c74b0471e9cba7ad8c",
"_shrinkwrap": null,
"_spec": "image-size@~0.3.5",
"_where": "F:\\tmp\\gitbook\\node_modules\\less",
"author": {
"email": "aditya@netroy.in",
"name": "netroy",
"url": "http://netroy.in/"
},
"bin": {
"image-size": "./bin/image-size"
},
"bugs": {
"url": "https://github.com/netroy/image-size/issues"
},
"dependencies": {},
"description": "get dimensions of any image file",
"devDependencies": {
"escomplex-js": "~0.1.4",
"expect.js": "~0.3.1",
"glob": "~4.0.6",
"jshint": "~2.5.6",
"mocha": "~1.21.5",
"sinon": "~1.10.3"
},
"directories": {},
"dist": {
"shasum": "83240eab2fb5b00b04aab8c74b0471e9cba7ad8c",
"tarball": "https://registry.npmjs.org/image-size/-/image-size-0.3.5.tgz"
},
"engines": {
"node": ">=0.10.0"
},
"gitHead": "ccef69913f1cac2cb88c5f6309d70a37cf097658",
"homepage": "https://github.com/netroy/image-size",
"keywords": [
"image",
"size",
"dimensions",
"resolution",
"width",
"height",
"png",
"jpeg",
"bmp",
"gif",
"psd",
"tiff",
"webp",
"svg"
],
"license": "MIT",
"main": "lib/index.js",
"maintainers": [
{
"email": "aditya@netroy.in",
"name": "netroy"
}
],
"name": "image-size",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/netroy/image-size.git"
},
"scripts": {
"test": "make"
},
"version": "0.3.5"
}