WIP - add extractor, generate snippet_data
This commit is contained in:
184
node_modules/@jimp/core/dist/utils/image-bitmap.js
generated
vendored
Normal file
184
node_modules/@jimp/core/dist/utils/image-bitmap.js
generated
vendored
Normal file
@ -0,0 +1,184 @@
|
||||
"use strict";
|
||||
|
||||
require("core-js/modules/es6.object.define-property");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.parseBitmap = parseBitmap;
|
||||
exports.getBuffer = getBuffer;
|
||||
exports.getBufferAsync = getBufferAsync;
|
||||
|
||||
var _fileType = _interopRequireDefault(require("file-type"));
|
||||
|
||||
var _exifParser = _interopRequireDefault(require("exif-parser"));
|
||||
|
||||
var _utils = require("@jimp/utils");
|
||||
|
||||
var constants = _interopRequireWildcard(require("../constants"));
|
||||
|
||||
var MIME = _interopRequireWildcard(require("./mime"));
|
||||
|
||||
var _promisify = _interopRequireDefault(require("./promisify"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function getMIMEFromBuffer(buffer, path) {
|
||||
var fileTypeFromBuffer = (0, _fileType.default)(buffer);
|
||||
|
||||
if (fileTypeFromBuffer) {
|
||||
// If fileType returns something for buffer, then return the mime given
|
||||
return fileTypeFromBuffer.mime;
|
||||
}
|
||||
|
||||
if (path) {
|
||||
// If a path is supplied, and fileType yields no results, then retry with MIME
|
||||
// Path can be either a file path or a url
|
||||
return MIME.getType(path);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/*
|
||||
* Automagically rotates an image based on its EXIF data (if present)
|
||||
* @param img a constants object
|
||||
*/
|
||||
|
||||
|
||||
function exifRotate(img) {
|
||||
var exif = img._exif;
|
||||
|
||||
if (exif && exif.tags && exif.tags.Orientation) {
|
||||
switch (img._exif.tags.Orientation) {
|
||||
case 1:
|
||||
// Horizontal (normal)
|
||||
// do nothing
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// Mirror horizontal
|
||||
img.mirror(true, false);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// Rotate 180
|
||||
img.rotate(180, false);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
// Mirror vertical
|
||||
img.mirror(false, true);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
// Mirror horizontal and rotate 270 CW
|
||||
img.rotate(-90, false).mirror(true, false);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
// Rotate 90 CW
|
||||
img.rotate(-90, false);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
// Mirror horizontal and rotate 90 CW
|
||||
img.rotate(90, false).mirror(true, false);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
// Rotate 270 CW
|
||||
img.rotate(-270, false);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
} // parses a bitmap from the constructor to the JIMP bitmap property
|
||||
|
||||
|
||||
function parseBitmap(data, path, cb) {
|
||||
var mime = getMIMEFromBuffer(data, path);
|
||||
|
||||
if (typeof mime !== 'string') {
|
||||
return cb(new Error('Could not find MIME for Buffer <' + path + '>'));
|
||||
}
|
||||
|
||||
this._originalMime = mime.toLowerCase();
|
||||
|
||||
try {
|
||||
var _mime = this.getMIME();
|
||||
|
||||
if (this.constructor.decoders[_mime]) {
|
||||
this.bitmap = this.constructor.decoders[_mime](data);
|
||||
} else {
|
||||
return _utils.throwError.call(this, 'Unsupported MIME type: ' + _mime, cb);
|
||||
}
|
||||
} catch (error) {
|
||||
return cb.call(this, error, this);
|
||||
}
|
||||
|
||||
try {
|
||||
this._exif = _exifParser.default.create(data).parse();
|
||||
exifRotate(this); // EXIF data
|
||||
} catch (error) {
|
||||
/* meh */
|
||||
}
|
||||
|
||||
cb.call(this, null, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
function compositeBitmapOverBackground(Jimp, image) {
|
||||
return new Jimp(image.bitmap.width, image.bitmap.height, image._background).composite(image, 0, 0).bitmap;
|
||||
}
|
||||
/**
|
||||
* Converts the image to a buffer
|
||||
* @param {string} mime the mime type of the image buffer to be created
|
||||
* @param {function(Error, Jimp)} cb a Node-style function to call with the buffer as the second argument
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
|
||||
|
||||
function getBuffer(mime, cb) {
|
||||
if (mime === constants.AUTO) {
|
||||
// allow auto MIME detection
|
||||
mime = this.getMIME();
|
||||
}
|
||||
|
||||
if (typeof mime !== 'string') {
|
||||
return _utils.throwError.call(this, 'mime must be a string', cb);
|
||||
}
|
||||
|
||||
if (typeof cb !== 'function') {
|
||||
return _utils.throwError.call(this, 'cb must be a function', cb);
|
||||
}
|
||||
|
||||
mime = mime.toLowerCase();
|
||||
|
||||
if (this._rgba && this.constructor.hasAlpha[mime]) {
|
||||
this.bitmap.data = Buffer.from(this.bitmap.data);
|
||||
} else {
|
||||
// when format doesn't support alpha
|
||||
// composite onto a new image so that the background shows through alpha channels
|
||||
this.bitmap.data = compositeBitmapOverBackground(this.constructor, this).data;
|
||||
}
|
||||
|
||||
if (this.constructor.encoders[mime]) {
|
||||
var buffer = this.constructor.encoders[mime](this);
|
||||
cb.call(this, null, buffer);
|
||||
} else {
|
||||
cb.call(this, 'Unsupported MIME type: ' + mime);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
function getBufferAsync(mime) {
|
||||
return (0, _promisify.default)(getBuffer, this, mime);
|
||||
}
|
||||
//# sourceMappingURL=image-bitmap.js.map
|
||||
1
node_modules/@jimp/core/dist/utils/image-bitmap.js.map
generated
vendored
Normal file
1
node_modules/@jimp/core/dist/utils/image-bitmap.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
64
node_modules/@jimp/core/dist/utils/mime.js
generated
vendored
Normal file
64
node_modules/@jimp/core/dist/utils/mime.js
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
|
||||
require("core-js/modules/es6.object.define-property");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getExtension = exports.getType = exports.addType = void 0;
|
||||
|
||||
require("core-js/modules/es6.regexp.split");
|
||||
|
||||
require("core-js/modules/es7.array.includes");
|
||||
|
||||
require("core-js/modules/es6.string.includes");
|
||||
|
||||
require("core-js/modules/web.dom.iterable");
|
||||
|
||||
require("core-js/modules/es6.array.iterator");
|
||||
|
||||
require("core-js/modules/es7.object.entries");
|
||||
|
||||
require("core-js/modules/es6.array.find");
|
||||
|
||||
var mimeTypes = {};
|
||||
|
||||
var findType = function findType(extension) {
|
||||
return Object.entries(mimeTypes).find(function (type) {
|
||||
return type[1].includes(extension);
|
||||
}) || [];
|
||||
};
|
||||
|
||||
var addType = function addType(mime, extensions) {
|
||||
mimeTypes[mime] = extensions;
|
||||
};
|
||||
/**
|
||||
* Lookup a mime type based on extension
|
||||
* @param {string} path path to find extension for
|
||||
* @returns {string} mime found mime type
|
||||
*/
|
||||
|
||||
|
||||
exports.addType = addType;
|
||||
|
||||
var getType = function getType(path) {
|
||||
var pathParts = path.split('/').slice(-1);
|
||||
var extension = pathParts[pathParts.length - 1].split('.')[1];
|
||||
var type = findType(extension);
|
||||
return type[0];
|
||||
};
|
||||
/**
|
||||
* Return file extension associated with a mime type
|
||||
* @param {string} type mime type to look up
|
||||
* @returns {string} extension file extension
|
||||
*/
|
||||
|
||||
|
||||
exports.getType = getType;
|
||||
|
||||
var getExtension = function getExtension(type) {
|
||||
return (mimeTypes[type.toLowerCase()] || [])[0];
|
||||
};
|
||||
|
||||
exports.getExtension = getExtension;
|
||||
//# sourceMappingURL=mime.js.map
|
||||
1
node_modules/@jimp/core/dist/utils/mime.js.map
generated
vendored
Normal file
1
node_modules/@jimp/core/dist/utils/mime.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/utils/mime.js"],"names":["mimeTypes","findType","extension","Object","entries","find","type","includes","addType","mime","extensions","getType","path","pathParts","split","slice","length","getExtension","toLowerCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAMA,SAAS,GAAG,EAAlB;;AAEA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAAAC,SAAS;AAAA,SACxBC,MAAM,CAACC,OAAP,CAAeJ,SAAf,EAA0BK,IAA1B,CAA+B,UAAAC,IAAI;AAAA,WAAIA,IAAI,CAAC,CAAD,CAAJ,CAAQC,QAAR,CAAiBL,SAAjB,CAAJ;AAAA,GAAnC,KAAuE,EAD/C;AAAA,CAA1B;;AAGO,IAAMM,OAAO,GAAG,SAAVA,OAAU,CAACC,IAAD,EAAOC,UAAP,EAAsB;AAC3CV,EAAAA,SAAS,CAACS,IAAD,CAAT,GAAkBC,UAAlB;AACD,CAFM;AAIP;;;;;;;;;AAKO,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAAAC,IAAI,EAAI;AAC7B,MAAMC,SAAS,GAAGD,IAAI,CAACE,KAAL,CAAW,GAAX,EAAgBC,KAAhB,CAAsB,CAAC,CAAvB,CAAlB;AACA,MAAMb,SAAS,GAAGW,SAAS,CAACA,SAAS,CAACG,MAAV,GAAmB,CAApB,CAAT,CAAgCF,KAAhC,CAAsC,GAAtC,EAA2C,CAA3C,CAAlB;AACA,MAAMR,IAAI,GAAGL,QAAQ,CAACC,SAAD,CAArB;AAEA,SAAOI,IAAI,CAAC,CAAD,CAAX;AACD,CANM;AAQP;;;;;;;;;AAKO,IAAMW,YAAY,GAAG,SAAfA,YAAe,CAAAX,IAAI;AAAA,SAAI,CAACN,SAAS,CAACM,IAAI,CAACY,WAAL,EAAD,CAAT,IAAiC,EAAlC,EAAsC,CAAtC,CAAJ;AAAA,CAAzB","sourcesContent":["const mimeTypes = {};\n\nconst findType = extension =>\n Object.entries(mimeTypes).find(type => type[1].includes(extension)) || [];\n\nexport const addType = (mime, extensions) => {\n mimeTypes[mime] = extensions;\n};\n\n/**\n * Lookup a mime type based on extension\n * @param {string} path path to find extension for\n * @returns {string} mime found mime type\n */\nexport const getType = path => {\n const pathParts = path.split('/').slice(-1);\n const extension = pathParts[pathParts.length - 1].split('.')[1];\n const type = findType(extension);\n\n return type[0];\n};\n\n/**\n * Return file extension associated with a mime type\n * @param {string} type mime type to look up\n * @returns {string} extension file extension\n */\nexport const getExtension = type => (mimeTypes[type.toLowerCase()] || [])[0];\n"],"file":"mime.js"}
|
||||
34
node_modules/@jimp/core/dist/utils/promisify.js
generated
vendored
Normal file
34
node_modules/@jimp/core/dist/utils/promisify.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
require("core-js/modules/es6.object.define-property");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
require("core-js/modules/es6.function.bind");
|
||||
|
||||
require("core-js/modules/es6.promise");
|
||||
|
||||
var promisify = function promisify(fun, ctx) {
|
||||
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
||||
args[_key - 2] = arguments[_key];
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
args.push(function (err, data) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
resolve(data);
|
||||
});
|
||||
fun.bind(ctx).apply(void 0, args);
|
||||
});
|
||||
};
|
||||
|
||||
var _default = promisify;
|
||||
exports.default = _default;
|
||||
module.exports = exports.default;
|
||||
//# sourceMappingURL=promisify.js.map
|
||||
1
node_modules/@jimp/core/dist/utils/promisify.js.map
generated
vendored
Normal file
1
node_modules/@jimp/core/dist/utils/promisify.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/utils/promisify.js"],"names":["promisify","fun","ctx","args","Promise","resolve","reject","push","err","data","bind"],"mappings":";;;;;;;;;;;;;AAAA,IAAMA,SAAS,GAAG,SAAZA,SAAY,CAACC,GAAD,EAAMC,GAAN;AAAA,oCAAcC,IAAd;AAAcA,IAAAA,IAAd;AAAA;;AAAA,SAChB,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;AAC/BH,IAAAA,IAAI,CAACI,IAAL,CAAU,UAACC,GAAD,EAAMC,IAAN,EAAe;AACvB,UAAID,GAAJ,EAAS;AACPF,QAAAA,MAAM,CAACE,GAAD,CAAN;AACD;;AAEDH,MAAAA,OAAO,CAACI,IAAD,CAAP;AACD,KAND;AAOAR,IAAAA,GAAG,CAACS,IAAJ,CAASR,GAAT,gBAAiBC,IAAjB;AACD,GATD,CADgB;AAAA,CAAlB;;eAYeH,S","sourcesContent":["const promisify = (fun, ctx, ...args) =>\n new Promise((resolve, reject) => {\n args.push((err, data) => {\n if (err) {\n reject(err);\n }\n\n resolve(data);\n });\n fun.bind(ctx)(...args);\n });\n\nexport default promisify;\n"],"file":"promisify.js"}
|
||||
Reference in New Issue
Block a user