初始化

This commit is contained in:
yziiy
2025-08-11 11:06:07 +08:00
parent 083bc37c00
commit 5607d11395
19772 changed files with 3108723 additions and 18 deletions

View File

@@ -0,0 +1,11 @@
# v0.9.3 (Tue Nov 26 2019)
#### 🐛 Bug Fix
- `@jimp/cli`, `@jimp/core`, `@jimp/custom`, `jimp`, `@jimp/plugin-blit`, `@jimp/plugin-blur`, `@jimp/plugin-circle`, `@jimp/plugin-color`, `@jimp/plugin-contain`, `@jimp/plugin-cover`, `@jimp/plugin-crop`, `@jimp/plugin-displace`, `@jimp/plugin-dither`, `@jimp/plugin-fisheye`, `@jimp/plugin-flip`, `@jimp/plugin-gaussian`, `@jimp/plugin-invert`, `@jimp/plugin-mask`, `@jimp/plugin-normalize`, `@jimp/plugin-print`, `@jimp/plugin-resize`, `@jimp/plugin-rotate`, `@jimp/plugin-scale`, `@jimp/plugin-shadow`, `@jimp/plugin-threshold`, `@jimp/plugins`, `@jimp/test-utils`, `@jimp/bmp`, `@jimp/gif`, `@jimp/jpeg`, `@jimp/png`, `@jimp/tiff`, `@jimp/types`, `@jimp/utils`
- Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 2
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))

21
uni_modules/UniDevTools/node_modules/@jimp/bmp/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Oliver Moran
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.

View File

@@ -0,0 +1,6 @@
<div align="center">
<img width="200" height="200"
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
<h1>@jimp/bmp</h1>
<p>Default Jimp bmp encoder/decoder.</p>
</div>

View File

@@ -0,0 +1,71 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _bmpJs = _interopRequireDefault(require("bmp-js"));
var _utils = require("@jimp/utils");
var MIME_TYPE = 'image/bmp';
var MIME_TYPE_SECOND = 'image/x-ms-bmp';
function toAGBR(image) {
return (0, _utils.scan)(image, 0, 0, image.bitmap.width, image.bitmap.height, function (x, y, index) {
var red = this.bitmap.data[index + 0];
var green = this.bitmap.data[index + 1];
var blue = this.bitmap.data[index + 2];
var alpha = this.bitmap.data[index + 3];
this.bitmap.data[index + 0] = alpha;
this.bitmap.data[index + 1] = blue;
this.bitmap.data[index + 2] = green;
this.bitmap.data[index + 3] = red;
}).bitmap;
}
function fromAGBR(bitmap) {
return (0, _utils.scan)({
bitmap: bitmap
}, 0, 0, bitmap.width, bitmap.height, function (x, y, index) {
var alpha = this.bitmap.data[index + 0];
var blue = this.bitmap.data[index + 1];
var green = this.bitmap.data[index + 2];
var red = this.bitmap.data[index + 3];
this.bitmap.data[index + 0] = red;
this.bitmap.data[index + 1] = green;
this.bitmap.data[index + 2] = blue;
this.bitmap.data[index + 3] = bitmap.is_with_alpha ? alpha : 0xff;
}).bitmap;
}
var decode = function decode(data) {
return fromAGBR(_bmpJs["default"].decode(data));
};
var encode = function encode(image) {
return _bmpJs["default"].encode(toAGBR(image)).data;
};
var _default = function _default() {
var _decoders, _encoders;
return {
mime: (0, _defineProperty2["default"])({}, MIME_TYPE, ['bmp']),
constants: {
MIME_BMP: MIME_TYPE,
MIME_X_MS_BMP: MIME_TYPE_SECOND
},
decoders: (_decoders = {}, (0, _defineProperty2["default"])(_decoders, MIME_TYPE, decode), (0, _defineProperty2["default"])(_decoders, MIME_TYPE_SECOND, decode), _decoders),
encoders: (_encoders = {}, (0, _defineProperty2["default"])(_encoders, MIME_TYPE, encode), (0, _defineProperty2["default"])(_encoders, MIME_TYPE_SECOND, encode), _encoders)
};
};
exports["default"] = _default;
module.exports = exports.default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":["MIME_TYPE","MIME_TYPE_SECOND","toAGBR","image","bitmap","width","height","x","y","index","red","data","green","blue","alpha","fromAGBR","is_with_alpha","decode","BMP","encode","mime","constants","MIME_BMP","MIME_X_MS_BMP","decoders","encoders"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA,IAAMA,SAAS,GAAG,WAAlB;AACA,IAAMC,gBAAgB,GAAG,gBAAzB;;AAEA,SAASC,MAAT,CAAgBC,KAAhB,EAAuB;AACrB,SAAO,iBAAKA,KAAL,EAAY,CAAZ,EAAe,CAAf,EAAkBA,KAAK,CAACC,MAAN,CAAaC,KAA/B,EAAsCF,KAAK,CAACC,MAAN,CAAaE,MAAnD,EAA2D,UAChEC,CADgE,EAEhEC,CAFgE,EAGhEC,KAHgE,EAIhE;AACA,QAAMC,GAAG,GAAG,KAAKN,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAZ;AACA,QAAMG,KAAK,GAAG,KAAKR,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAd;AACA,QAAMI,IAAI,GAAG,KAAKT,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAb;AACA,QAAMK,KAAK,GAAG,KAAKV,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAd;AAEA,SAAKL,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BK,KAA9B;AACA,SAAKV,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BI,IAA9B;AACA,SAAKT,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BG,KAA9B;AACA,SAAKR,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BC,GAA9B;AACD,GAdM,EAcJN,MAdH;AAeD;;AAED,SAASW,QAAT,CAAkBX,MAAlB,EAA0B;AACxB,SAAO,iBAAK;AAAEA,IAAAA,MAAM,EAANA;AAAF,GAAL,EAAiB,CAAjB,EAAoB,CAApB,EAAuBA,MAAM,CAACC,KAA9B,EAAqCD,MAAM,CAACE,MAA5C,EAAoD,UACzDC,CADyD,EAEzDC,CAFyD,EAGzDC,KAHyD,EAIzD;AACA,QAAMK,KAAK,GAAG,KAAKV,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAd;AACA,QAAMI,IAAI,GAAG,KAAKT,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAb;AACA,QAAMG,KAAK,GAAG,KAAKR,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAd;AACA,QAAMC,GAAG,GAAG,KAAKN,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAZ;AAEA,SAAKL,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BC,GAA9B;AACA,SAAKN,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BG,KAA9B;AACA,SAAKR,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BI,IAA9B;AACA,SAAKT,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BL,MAAM,CAACY,aAAP,GAAuBF,KAAvB,GAA+B,IAA7D;AACD,GAdM,EAcJV,MAdH;AAeD;;AAED,IAAMa,MAAM,GAAG,SAATA,MAAS,CAAAN,IAAI;AAAA,SAAII,QAAQ,CAACG,kBAAID,MAAJ,CAAWN,IAAX,CAAD,CAAZ;AAAA,CAAnB;;AACA,IAAMQ,MAAM,GAAG,SAATA,MAAS,CAAAhB,KAAK;AAAA,SAAIe,kBAAIC,MAAJ,CAAWjB,MAAM,CAACC,KAAD,CAAjB,EAA0BQ,IAA9B;AAAA,CAApB;;eAEe;AAAA;;AAAA,SAAO;AACpBS,IAAAA,IAAI,uCAAKpB,SAAL,EAAiB,CAAC,KAAD,CAAjB,CADgB;AAGpBqB,IAAAA,SAAS,EAAE;AACTC,MAAAA,QAAQ,EAAEtB,SADD;AAETuB,MAAAA,aAAa,EAAEtB;AAFN,KAHS;AAQpBuB,IAAAA,QAAQ,+DACLxB,SADK,EACOiB,MADP,+CAELhB,gBAFK,EAEcgB,MAFd,aARY;AAapBQ,IAAAA,QAAQ,+DACLzB,SADK,EACOmB,MADP,+CAELlB,gBAFK,EAEckB,MAFd;AAbY,GAAP;AAAA,C","sourcesContent":["import BMP from 'bmp-js';\nimport { scan } from '@jimp/utils';\n\nconst MIME_TYPE = 'image/bmp';\nconst MIME_TYPE_SECOND = 'image/x-ms-bmp';\n\nfunction toAGBR(image) {\n return scan(image, 0, 0, image.bitmap.width, image.bitmap.height, function(\n x,\n y,\n index\n ) {\n const red = this.bitmap.data[index + 0];\n const green = this.bitmap.data[index + 1];\n const blue = this.bitmap.data[index + 2];\n const alpha = this.bitmap.data[index + 3];\n\n this.bitmap.data[index + 0] = alpha;\n this.bitmap.data[index + 1] = blue;\n this.bitmap.data[index + 2] = green;\n this.bitmap.data[index + 3] = red;\n }).bitmap;\n}\n\nfunction fromAGBR(bitmap) {\n return scan({ bitmap }, 0, 0, bitmap.width, bitmap.height, function(\n x,\n y,\n index\n ) {\n const alpha = this.bitmap.data[index + 0];\n const blue = this.bitmap.data[index + 1];\n const green = this.bitmap.data[index + 2];\n const red = this.bitmap.data[index + 3];\n\n this.bitmap.data[index + 0] = red;\n this.bitmap.data[index + 1] = green;\n this.bitmap.data[index + 2] = blue;\n this.bitmap.data[index + 3] = bitmap.is_with_alpha ? alpha : 0xff;\n }).bitmap;\n}\n\nconst decode = data => fromAGBR(BMP.decode(data));\nconst encode = image => BMP.encode(toAGBR(image)).data;\n\nexport default () => ({\n mime: { [MIME_TYPE]: ['bmp'] },\n\n constants: {\n MIME_BMP: MIME_TYPE,\n MIME_X_MS_BMP: MIME_TYPE_SECOND\n },\n\n decoders: {\n [MIME_TYPE]: decode,\n [MIME_TYPE_SECOND]: decode\n },\n\n encoders: {\n [MIME_TYPE]: encode,\n [MIME_TYPE_SECOND]: encode\n }\n});\n"],"file":"index.js"}

View File

@@ -0,0 +1,70 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _bmpJs = _interopRequireDefault(require("bmp-js"));
var _utils = require("@jimp/utils");
var MIME_TYPE = 'image/bmp';
var MIME_TYPE_SECOND = 'image/x-ms-bmp';
function toAGBR(image) {
return (0, _utils.scan)(image, 0, 0, image.bitmap.width, image.bitmap.height, function (x, y, index) {
var red = this.bitmap.data[index + 0];
var green = this.bitmap.data[index + 1];
var blue = this.bitmap.data[index + 2];
var alpha = this.bitmap.data[index + 3];
this.bitmap.data[index + 0] = alpha;
this.bitmap.data[index + 1] = blue;
this.bitmap.data[index + 2] = green;
this.bitmap.data[index + 3] = red;
}).bitmap;
}
function fromAGBR(bitmap) {
return (0, _utils.scan)({
bitmap: bitmap
}, 0, 0, bitmap.width, bitmap.height, function (x, y, index) {
var alpha = this.bitmap.data[index + 0];
var blue = this.bitmap.data[index + 1];
var green = this.bitmap.data[index + 2];
var red = this.bitmap.data[index + 3];
this.bitmap.data[index + 0] = red;
this.bitmap.data[index + 1] = green;
this.bitmap.data[index + 2] = blue;
this.bitmap.data[index + 3] = bitmap.is_with_alpha ? alpha : 0xff;
}).bitmap;
}
var decode = function decode(data) {
return fromAGBR(_bmpJs["default"].decode(data));
};
var encode = function encode(image) {
return _bmpJs["default"].encode(toAGBR(image)).data;
};
var _default = function _default() {
var _decoders, _encoders;
return {
mime: (0, _defineProperty2["default"])({}, MIME_TYPE, ['bmp']),
constants: {
MIME_BMP: MIME_TYPE,
MIME_X_MS_BMP: MIME_TYPE_SECOND
},
decoders: (_decoders = {}, (0, _defineProperty2["default"])(_decoders, MIME_TYPE, decode), (0, _defineProperty2["default"])(_decoders, MIME_TYPE_SECOND, decode), _decoders),
encoders: (_encoders = {}, (0, _defineProperty2["default"])(_encoders, MIME_TYPE, encode), (0, _defineProperty2["default"])(_encoders, MIME_TYPE_SECOND, encode), _encoders)
};
};
exports["default"] = _default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":["MIME_TYPE","MIME_TYPE_SECOND","toAGBR","image","bitmap","width","height","x","y","index","red","data","green","blue","alpha","fromAGBR","is_with_alpha","decode","BMP","encode","mime","constants","MIME_BMP","MIME_X_MS_BMP","decoders","encoders"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA,IAAMA,SAAS,GAAG,WAAlB;AACA,IAAMC,gBAAgB,GAAG,gBAAzB;;AAEA,SAASC,MAAT,CAAgBC,KAAhB,EAAuB;AACrB,SAAO,iBAAKA,KAAL,EAAY,CAAZ,EAAe,CAAf,EAAkBA,KAAK,CAACC,MAAN,CAAaC,KAA/B,EAAsCF,KAAK,CAACC,MAAN,CAAaE,MAAnD,EAA2D,UAChEC,CADgE,EAEhEC,CAFgE,EAGhEC,KAHgE,EAIhE;AACA,QAAMC,GAAG,GAAG,KAAKN,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAZ;AACA,QAAMG,KAAK,GAAG,KAAKR,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAd;AACA,QAAMI,IAAI,GAAG,KAAKT,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAb;AACA,QAAMK,KAAK,GAAG,KAAKV,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAd;AAEA,SAAKL,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BK,KAA9B;AACA,SAAKV,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BI,IAA9B;AACA,SAAKT,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BG,KAA9B;AACA,SAAKR,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BC,GAA9B;AACD,GAdM,EAcJN,MAdH;AAeD;;AAED,SAASW,QAAT,CAAkBX,MAAlB,EAA0B;AACxB,SAAO,iBAAK;AAAEA,IAAAA,MAAM,EAANA;AAAF,GAAL,EAAiB,CAAjB,EAAoB,CAApB,EAAuBA,MAAM,CAACC,KAA9B,EAAqCD,MAAM,CAACE,MAA5C,EAAoD,UACzDC,CADyD,EAEzDC,CAFyD,EAGzDC,KAHyD,EAIzD;AACA,QAAMK,KAAK,GAAG,KAAKV,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAd;AACA,QAAMI,IAAI,GAAG,KAAKT,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAb;AACA,QAAMG,KAAK,GAAG,KAAKR,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAd;AACA,QAAMC,GAAG,GAAG,KAAKN,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,CAAZ;AAEA,SAAKL,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BC,GAA9B;AACA,SAAKN,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BG,KAA9B;AACA,SAAKR,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BI,IAA9B;AACA,SAAKT,MAAL,CAAYO,IAAZ,CAAiBF,KAAK,GAAG,CAAzB,IAA8BL,MAAM,CAACY,aAAP,GAAuBF,KAAvB,GAA+B,IAA7D;AACD,GAdM,EAcJV,MAdH;AAeD;;AAED,IAAMa,MAAM,GAAG,SAATA,MAAS,CAAAN,IAAI;AAAA,SAAII,QAAQ,CAACG,kBAAID,MAAJ,CAAWN,IAAX,CAAD,CAAZ;AAAA,CAAnB;;AACA,IAAMQ,MAAM,GAAG,SAATA,MAAS,CAAAhB,KAAK;AAAA,SAAIe,kBAAIC,MAAJ,CAAWjB,MAAM,CAACC,KAAD,CAAjB,EAA0BQ,IAA9B;AAAA,CAApB;;eAEe;AAAA;;AAAA,SAAO;AACpBS,IAAAA,IAAI,uCAAKpB,SAAL,EAAiB,CAAC,KAAD,CAAjB,CADgB;AAGpBqB,IAAAA,SAAS,EAAE;AACTC,MAAAA,QAAQ,EAAEtB,SADD;AAETuB,MAAAA,aAAa,EAAEtB;AAFN,KAHS;AAQpBuB,IAAAA,QAAQ,+DACLxB,SADK,EACOiB,MADP,+CAELhB,gBAFK,EAEcgB,MAFd,aARY;AAapBQ,IAAAA,QAAQ,+DACLzB,SADK,EACOmB,MADP,+CAELlB,gBAFK,EAEckB,MAFd;AAbY,GAAP;AAAA,C","sourcesContent":["import BMP from 'bmp-js';\nimport { scan } from '@jimp/utils';\n\nconst MIME_TYPE = 'image/bmp';\nconst MIME_TYPE_SECOND = 'image/x-ms-bmp';\n\nfunction toAGBR(image) {\n return scan(image, 0, 0, image.bitmap.width, image.bitmap.height, function(\n x,\n y,\n index\n ) {\n const red = this.bitmap.data[index + 0];\n const green = this.bitmap.data[index + 1];\n const blue = this.bitmap.data[index + 2];\n const alpha = this.bitmap.data[index + 3];\n\n this.bitmap.data[index + 0] = alpha;\n this.bitmap.data[index + 1] = blue;\n this.bitmap.data[index + 2] = green;\n this.bitmap.data[index + 3] = red;\n }).bitmap;\n}\n\nfunction fromAGBR(bitmap) {\n return scan({ bitmap }, 0, 0, bitmap.width, bitmap.height, function(\n x,\n y,\n index\n ) {\n const alpha = this.bitmap.data[index + 0];\n const blue = this.bitmap.data[index + 1];\n const green = this.bitmap.data[index + 2];\n const red = this.bitmap.data[index + 3];\n\n this.bitmap.data[index + 0] = red;\n this.bitmap.data[index + 1] = green;\n this.bitmap.data[index + 2] = blue;\n this.bitmap.data[index + 3] = bitmap.is_with_alpha ? alpha : 0xff;\n }).bitmap;\n}\n\nconst decode = data => fromAGBR(BMP.decode(data));\nconst encode = image => BMP.encode(toAGBR(image)).data;\n\nexport default () => ({\n mime: { [MIME_TYPE]: ['bmp'] },\n\n constants: {\n MIME_BMP: MIME_TYPE,\n MIME_X_MS_BMP: MIME_TYPE_SECOND\n },\n\n decoders: {\n [MIME_TYPE]: decode,\n [MIME_TYPE_SECOND]: decode\n },\n\n encoders: {\n [MIME_TYPE]: encode,\n [MIME_TYPE_SECOND]: encode\n }\n});\n"],"file":"index.js"}

View File

@@ -0,0 +1,24 @@
import { DecoderFn, EncoderFn } from '@jimp/core';
interface Bmp {
constants: {
MIME_BMP: 'image/bmp';
MIME_X_MS_BMP: 'image/x-ms-bmp';
}
mime: {
'image/bmp': string[]
}
decoders: {
'image/bmp': DecoderFn
'image/x-ms-bmp': DecoderFn
}
encoders: {
'image/bmp': EncoderFn
'image/x-ms-bmp': EncoderFn
}
}
export default function(): Bmp;

View File

@@ -0,0 +1,39 @@
{
"name": "@jimp/bmp",
"version": "0.10.3",
"description": "Default Jimp bmp encoder/decoder.",
"main": "dist/index.js",
"module": "es/index.js",
"types": "index.d.ts",
"scripts": {
"test": "cross-env BABEL_ENV=test mocha --require @babel/register",
"test:watch": "npm run test -- --reporter min --watch",
"test:coverage": "nyc npm run test",
"build": "npm run build:node:production && npm run build:module",
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
"build:debug": "npm run build:node:debug",
"build:module": "cross-env BABEL_ENV=module babel src -d es --source-maps --config-file ../../babel.config.js",
"build:node": "babel src -d dist --source-maps --config-file ../../babel.config.js",
"build:node:debug": "cross-env BABEL_ENV=development npm run build:node",
"build:node:production": "cross-env BABEL_ENV=production npm run build:node"
},
"author": "",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.7.2",
"@jimp/utils": "^0.10.3",
"bmp-js": "^0.1.0",
"core-js": "^3.4.1"
},
"peerDependencies": {
"@jimp/custom": ">=0.3.5"
},
"devDependencies": {
"@jimp/custom": "^0.10.3",
"@jimp/test-utils": "^0.10.3"
},
"publishConfig": {
"access": "public"
},
"gitHead": "37197106eae5c26231018dfdc0254422f6b43927"
}

View File

@@ -0,0 +1,63 @@
import BMP from 'bmp-js';
import { scan } from '@jimp/utils';
const MIME_TYPE = 'image/bmp';
const MIME_TYPE_SECOND = 'image/x-ms-bmp';
function toAGBR(image) {
return scan(image, 0, 0, image.bitmap.width, image.bitmap.height, function(
x,
y,
index
) {
const red = this.bitmap.data[index + 0];
const green = this.bitmap.data[index + 1];
const blue = this.bitmap.data[index + 2];
const alpha = this.bitmap.data[index + 3];
this.bitmap.data[index + 0] = alpha;
this.bitmap.data[index + 1] = blue;
this.bitmap.data[index + 2] = green;
this.bitmap.data[index + 3] = red;
}).bitmap;
}
function fromAGBR(bitmap) {
return scan({ bitmap }, 0, 0, bitmap.width, bitmap.height, function(
x,
y,
index
) {
const alpha = this.bitmap.data[index + 0];
const blue = this.bitmap.data[index + 1];
const green = this.bitmap.data[index + 2];
const red = this.bitmap.data[index + 3];
this.bitmap.data[index + 0] = red;
this.bitmap.data[index + 1] = green;
this.bitmap.data[index + 2] = blue;
this.bitmap.data[index + 3] = bitmap.is_with_alpha ? alpha : 0xff;
}).bitmap;
}
const decode = data => fromAGBR(BMP.decode(data));
const encode = image => BMP.encode(toAGBR(image)).data;
export default () => ({
mime: { [MIME_TYPE]: ['bmp'] },
constants: {
MIME_BMP: MIME_TYPE,
MIME_X_MS_BMP: MIME_TYPE_SECOND
},
decoders: {
[MIME_TYPE]: decode,
[MIME_TYPE_SECOND]: decode
},
encoders: {
[MIME_TYPE]: encode,
[MIME_TYPE_SECOND]: encode
}
});

View File

@@ -0,0 +1,54 @@
/* eslint-disable no-control-regex */
import { Jimp, getTestDir } from '@jimp/test-utils';
import configure from '@jimp/custom';
import bmp from '../src';
const jimp = configure({ types: [bmp] }, Jimp);
describe('BMP', () => {
const imagesDir = getTestDir(__dirname) + '/images';
it('load BMP', async () => {
const image = await jimp.read(imagesDir + '/windows95.bmp');
image.getPixelColor(10, 10).should.be.equal(0xeff7f7ff);
image.getPixelColor(150, 80).should.be.equal(0x73add6ff);
image.getPixelColor(190, 200).should.be.equal(0xf7c300ff);
});
it('export BMP', async () => {
const image = await jimp.read({
width: 3,
height: 3,
data: [
0xff0000ff,
0xff0080ff,
0xff00ffff,
0xff0080ff,
0xff00ffff,
0x8000ffff,
0xff00ffff,
0x8000ffff,
0x0000ffff
]
});
const buffer = await image.getBufferAsync('image/bmp');
buffer.toString().should.match(/^BMZ\u0000/);
});
it('uses correct colors for BMP', async function() {
this.timeout(4000);
const expectedImg = await jimp.read(
getTestDir(__dirname) + '/images/windows95.png'
);
const image = await jimp.read(
getTestDir(__dirname) + '/images/windows95.bmp'
);
image.bitmap.data.should.be.deepEqual(expectedImg.bitmap.data);
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

View File

@@ -0,0 +1,54 @@
# v0.10.2 (Tue Apr 14 2020)
#### 🐛 Bug Fix
- Rewrite handling EXIF orientation — add tests, make it plugin-independent [#875](https://github.com/oliver-moran/jimp/pull/875) ([@skalee](https://github.com/skalee))
#### Authors: 1
- Sebastian Skałacki ([@skalee](https://github.com/skalee))
---
# v0.10.0 (Mon Mar 30 2020)
#### 🚀 Enhancement
- Properly split constructor and instance types [#867](https://github.com/oliver-moran/jimp/pull/867) ([@forivall](https://github.com/forivall))
#### Authors: 1
- Emily Marigold Klassen ([@forivall](https://github.com/forivall))
---
# v0.9.6 (Wed Mar 18 2020)
#### 🐛 Bug Fix
- Relax mkdirp dependency to allow newer minimist [#857](https://github.com/oliver-moran/jimp/pull/857) ([@Den-dp](https://github.com/Den-dp))
#### 🏠 Internal
- Fix TypeScript error on 'next' [#858](https://github.com/oliver-moran/jimp/pull/858) ([@crutchcorn](https://github.com/crutchcorn))
#### Authors: 2
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))
- Denis Bendrikov ([@Den-dp](https://github.com/Den-dp))
---
# v0.9.3 (Tue Nov 26 2019)
#### 🐛 Bug Fix
- `@jimp/cli`, `@jimp/core`, `@jimp/custom`, `jimp`, `@jimp/plugin-blit`, `@jimp/plugin-blur`, `@jimp/plugin-circle`, `@jimp/plugin-color`, `@jimp/plugin-contain`, `@jimp/plugin-cover`, `@jimp/plugin-crop`, `@jimp/plugin-displace`, `@jimp/plugin-dither`, `@jimp/plugin-fisheye`, `@jimp/plugin-flip`, `@jimp/plugin-gaussian`, `@jimp/plugin-invert`, `@jimp/plugin-mask`, `@jimp/plugin-normalize`, `@jimp/plugin-print`, `@jimp/plugin-resize`, `@jimp/plugin-rotate`, `@jimp/plugin-scale`, `@jimp/plugin-shadow`, `@jimp/plugin-threshold`, `@jimp/plugins`, `@jimp/test-utils`, `@jimp/bmp`, `@jimp/gif`, `@jimp/jpeg`, `@jimp/png`, `@jimp/tiff`, `@jimp/types`, `@jimp/utils`
- Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie))
- `@jimp/core`
- Follow redirects [#789](https://github.com/oliver-moran/jimp/pull/789) ([@SaWey](https://github.com/SaWey) sander@solora.be)
#### Authors: 2
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Oliver Moran
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.

View File

@@ -0,0 +1,52 @@
<div align="center">
<img width="200" height="200"
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
<h1>@jimp/core</h1>
</div>
The main Jimp class. This class can be extended with types and bitmap manipulation functions. Out of the box it does not support any image type.
## Available Methods
### Jimp
The Jimp class constructor.
### addConstants
Add constant or static methods to the Jimp constructor.
```js
addConstants({
MIME_SPECIAL: 'image/special'
});
```
### addJimpMethods
Add a bitmap manipulation method to Jimp constructor. These method should return this so that the function can be chain-able.
```js
addJimpMethods({
cropCrazy: function() {
// Your custom image manipulation method
return this;
}
})
const image = await Jimp.read(...);
image.resize(10, Jimp.AUTO),
.cropCrazy();
await image.writeAsync('test.png');
```
### addType
Add a image mime type to Jimp constructor. First argument is a mime type and the second is an array of file extension for that type.
```js
addType('image/special', ['spec', 'special']);
```

View File

@@ -0,0 +1,214 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.srcOver = srcOver;
exports.dstOver = dstOver;
exports.multiply = multiply;
exports.screen = screen;
exports.overlay = overlay;
exports.darken = darken;
exports.lighten = lighten;
exports.hardLight = hardLight;
exports.difference = difference;
exports.exclusion = exclusion;
function srcOver(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var r = (src.r * src.a + dst.r * dst.a * (1 - src.a)) / a;
var g = (src.g * src.a + dst.g * dst.a * (1 - src.a)) / a;
var b = (src.b * src.a + dst.b * dst.a * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function dstOver(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var r = (dst.r * dst.a + src.r * src.a * (1 - dst.a)) / a;
var g = (dst.g * dst.a + src.g * src.a * (1 - dst.a)) / a;
var b = (dst.b * dst.a + src.b * src.a * (1 - dst.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function multiply(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function screen(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (sra * dst.a + dra * src.a - sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (sga * dst.a + dga * src.a - sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (sba * dst.a + dba * src.a - sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function overlay(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (2 * dra <= dst.a ? 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a) : sra * (1 + dst.a) + dra * (1 + src.a) - 2 * dra * sra - dst.a * src.a) / a;
var g = (2 * dga <= dst.a ? 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a) : sga * (1 + dst.a) + dga * (1 + src.a) - 2 * dga * sga - dst.a * src.a) / a;
var b = (2 * dba <= dst.a ? 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a) : sba * (1 + dst.a) + dba * (1 + src.a) - 2 * dba * sba - dst.a * src.a) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function darken(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (Math.min(sra * dst.a, dra * src.a) + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (Math.min(sga * dst.a, dga * src.a) + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (Math.min(sba * dst.a, dba * src.a) + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function lighten(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (Math.max(sra * dst.a, dra * src.a) + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (Math.max(sga * dst.a, dga * src.a) + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (Math.max(sba * dst.a, dba * src.a) + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function hardLight(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (2 * sra <= src.a ? 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a) : sra * (1 + dst.a) + dra * (1 + src.a) - 2 * dra * sra - dst.a * src.a) / a;
var g = (2 * sga <= src.a ? 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a) : sga * (1 + dst.a) + dga * (1 + src.a) - 2 * dga * sga - dst.a * src.a) / a;
var b = (2 * sba <= src.a ? 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a) : sba * (1 + dst.a) + dba * (1 + src.a) - 2 * dba * sba - dst.a * src.a) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function difference(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (sra + dra - 2 * Math.min(sra * dst.a, dra * src.a)) / a;
var g = (sga + dga - 2 * Math.min(sga * dst.a, dga * src.a)) / a;
var b = (sba + dba - 2 * Math.min(sba * dst.a, dba * src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function exclusion(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (sra * dst.a + dra * src.a - 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (sga * dst.a + dga * src.a - 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (sba * dst.a + dba * src.a - 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
//# sourceMappingURL=composite-modes.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,96 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = composite;
var _utils = require("@jimp/utils");
var constants = _interopRequireWildcard(require("../constants"));
var compositeModes = _interopRequireWildcard(require("./composite-modes"));
/**
* Composites a source image over to this image respecting alpha channels
* @param {Jimp} src the source Jimp instance
* @param {number} x the x position to blit the image
* @param {number} y the y position to blit the image
* @param {object} options determine what mode to use
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
function composite(src, x, y) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var cb = arguments.length > 4 ? arguments[4] : undefined;
if (typeof options === 'function') {
cb = options;
options = {};
}
if (!(src instanceof this.constructor)) {
return _utils.throwError.call(this, 'The source must be a Jimp image', cb);
}
if (typeof x !== 'number' || typeof y !== 'number') {
return _utils.throwError.call(this, 'x and y must be numbers', cb);
}
var _options = options,
mode = _options.mode,
opacitySource = _options.opacitySource,
opacityDest = _options.opacityDest;
if (!mode) {
mode = constants.BLEND_SOURCE_OVER;
}
if (typeof opacitySource !== 'number' || opacitySource < 0 || opacitySource > 1) {
opacitySource = 1.0;
}
if (typeof opacityDest !== 'number' || opacityDest < 0 || opacityDest > 1) {
opacityDest = 1.0;
}
var blendmode = compositeModes[mode]; // round input
x = Math.round(x);
y = Math.round(y);
var baseImage = this;
if (opacityDest !== 1.0) {
baseImage.opacity(opacityDest);
}
src.scanQuiet(0, 0, src.bitmap.width, src.bitmap.height, function (sx, sy, idx) {
var dstIdx = baseImage.getPixelIndex(x + sx, y + sy, constants.EDGE_CROP);
var blended = blendmode({
r: this.bitmap.data[idx + 0] / 255,
g: this.bitmap.data[idx + 1] / 255,
b: this.bitmap.data[idx + 2] / 255,
a: this.bitmap.data[idx + 3] / 255
}, {
r: baseImage.bitmap.data[dstIdx + 0] / 255,
g: baseImage.bitmap.data[dstIdx + 1] / 255,
b: baseImage.bitmap.data[dstIdx + 2] / 255,
a: baseImage.bitmap.data[dstIdx + 3] / 255
}, opacitySource);
baseImage.bitmap.data[dstIdx + 0] = this.constructor.limit255(blended.r * 255);
baseImage.bitmap.data[dstIdx + 1] = this.constructor.limit255(blended.g * 255);
baseImage.bitmap.data[dstIdx + 2] = this.constructor.limit255(blended.b * 255);
baseImage.bitmap.data[dstIdx + 3] = this.constructor.limit255(blended.a * 255);
});
if ((0, _utils.isNodePattern)(cb)) {
cb.call(this, null, this);
}
return this;
}
module.exports = exports.default;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EDGE_CROP = exports.EDGE_WRAP = exports.EDGE_EXTEND = exports.BLEND_EXCLUSION = exports.BLEND_DIFFERENCE = exports.BLEND_HARDLIGHT = exports.BLEND_LIGHTEN = exports.BLEND_DARKEN = exports.BLEND_OVERLAY = exports.BLEND_SCREEN = exports.BLEND_MULTIPLY = exports.BLEND_DESTINATION_OVER = exports.BLEND_SOURCE_OVER = exports.VERTICAL_ALIGN_BOTTOM = exports.VERTICAL_ALIGN_MIDDLE = exports.VERTICAL_ALIGN_TOP = exports.HORIZONTAL_ALIGN_RIGHT = exports.HORIZONTAL_ALIGN_CENTER = exports.HORIZONTAL_ALIGN_LEFT = exports.AUTO = void 0;
// used to auto resizing etc.
var AUTO = -1; // Align modes for cover, contain, bit masks
exports.AUTO = AUTO;
var HORIZONTAL_ALIGN_LEFT = 1;
exports.HORIZONTAL_ALIGN_LEFT = HORIZONTAL_ALIGN_LEFT;
var HORIZONTAL_ALIGN_CENTER = 2;
exports.HORIZONTAL_ALIGN_CENTER = HORIZONTAL_ALIGN_CENTER;
var HORIZONTAL_ALIGN_RIGHT = 4;
exports.HORIZONTAL_ALIGN_RIGHT = HORIZONTAL_ALIGN_RIGHT;
var VERTICAL_ALIGN_TOP = 8;
exports.VERTICAL_ALIGN_TOP = VERTICAL_ALIGN_TOP;
var VERTICAL_ALIGN_MIDDLE = 16;
exports.VERTICAL_ALIGN_MIDDLE = VERTICAL_ALIGN_MIDDLE;
var VERTICAL_ALIGN_BOTTOM = 32; // blend modes
exports.VERTICAL_ALIGN_BOTTOM = VERTICAL_ALIGN_BOTTOM;
var BLEND_SOURCE_OVER = 'srcOver';
exports.BLEND_SOURCE_OVER = BLEND_SOURCE_OVER;
var BLEND_DESTINATION_OVER = 'dstOver';
exports.BLEND_DESTINATION_OVER = BLEND_DESTINATION_OVER;
var BLEND_MULTIPLY = 'multiply';
exports.BLEND_MULTIPLY = BLEND_MULTIPLY;
var BLEND_SCREEN = 'screen';
exports.BLEND_SCREEN = BLEND_SCREEN;
var BLEND_OVERLAY = 'overlay';
exports.BLEND_OVERLAY = BLEND_OVERLAY;
var BLEND_DARKEN = 'darken';
exports.BLEND_DARKEN = BLEND_DARKEN;
var BLEND_LIGHTEN = 'lighten';
exports.BLEND_LIGHTEN = BLEND_LIGHTEN;
var BLEND_HARDLIGHT = 'hardLight';
exports.BLEND_HARDLIGHT = BLEND_HARDLIGHT;
var BLEND_DIFFERENCE = 'difference';
exports.BLEND_DIFFERENCE = BLEND_DIFFERENCE;
var BLEND_EXCLUSION = 'exclusion'; // Edge Handling
exports.BLEND_EXCLUSION = BLEND_EXCLUSION;
var EDGE_EXTEND = 1;
exports.EDGE_EXTEND = EDGE_EXTEND;
var EDGE_WRAP = 2;
exports.EDGE_WRAP = EDGE_WRAP;
var EDGE_CROP = 3;
exports.EDGE_CROP = EDGE_CROP;
//# sourceMappingURL=constants.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/constants.js"],"names":["AUTO","HORIZONTAL_ALIGN_LEFT","HORIZONTAL_ALIGN_CENTER","HORIZONTAL_ALIGN_RIGHT","VERTICAL_ALIGN_TOP","VERTICAL_ALIGN_MIDDLE","VERTICAL_ALIGN_BOTTOM","BLEND_SOURCE_OVER","BLEND_DESTINATION_OVER","BLEND_MULTIPLY","BLEND_SCREEN","BLEND_OVERLAY","BLEND_DARKEN","BLEND_LIGHTEN","BLEND_HARDLIGHT","BLEND_DIFFERENCE","BLEND_EXCLUSION","EDGE_EXTEND","EDGE_WRAP","EDGE_CROP"],"mappings":";;;;;;AAAA;AACO,IAAMA,IAAI,GAAG,CAAC,CAAd,C,CAEP;;;AACO,IAAMC,qBAAqB,GAAG,CAA9B;;AACA,IAAMC,uBAAuB,GAAG,CAAhC;;AACA,IAAMC,sBAAsB,GAAG,CAA/B;;AAEA,IAAMC,kBAAkB,GAAG,CAA3B;;AACA,IAAMC,qBAAqB,GAAG,EAA9B;;AACA,IAAMC,qBAAqB,GAAG,EAA9B,C,CAEP;;;AACO,IAAMC,iBAAiB,GAAG,SAA1B;;AACA,IAAMC,sBAAsB,GAAG,SAA/B;;AACA,IAAMC,cAAc,GAAG,UAAvB;;AACA,IAAMC,YAAY,GAAG,QAArB;;AACA,IAAMC,aAAa,GAAG,SAAtB;;AACA,IAAMC,YAAY,GAAG,QAArB;;AACA,IAAMC,aAAa,GAAG,SAAtB;;AACA,IAAMC,eAAe,GAAG,WAAxB;;AACA,IAAMC,gBAAgB,GAAG,YAAzB;;AACA,IAAMC,eAAe,GAAG,WAAxB,C,CAEP;;;AACO,IAAMC,WAAW,GAAG,CAApB;;AACA,IAAMC,SAAS,GAAG,CAAlB;;AACA,IAAMC,SAAS,GAAG,CAAlB","sourcesContent":["// used to auto resizing etc.\nexport const AUTO = -1;\n\n// Align modes for cover, contain, bit masks\nexport const HORIZONTAL_ALIGN_LEFT = 1;\nexport const HORIZONTAL_ALIGN_CENTER = 2;\nexport const HORIZONTAL_ALIGN_RIGHT = 4;\n\nexport const VERTICAL_ALIGN_TOP = 8;\nexport const VERTICAL_ALIGN_MIDDLE = 16;\nexport const VERTICAL_ALIGN_BOTTOM = 32;\n\n// blend modes\nexport const BLEND_SOURCE_OVER = 'srcOver';\nexport const BLEND_DESTINATION_OVER = 'dstOver';\nexport const BLEND_MULTIPLY = 'multiply';\nexport const BLEND_SCREEN = 'screen';\nexport const BLEND_OVERLAY = 'overlay';\nexport const BLEND_DARKEN = 'darken';\nexport const BLEND_LIGHTEN = 'lighten';\nexport const BLEND_HARDLIGHT = 'hardLight';\nexport const BLEND_DIFFERENCE = 'difference';\nexport const BLEND_EXCLUSION = 'exclusion';\n\n// Edge Handling\nexport const EDGE_EXTEND = 1;\nexport const EDGE_WRAP = 2;\nexport const EDGE_CROP = 3;\n"],"file":"constants.js"}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,173 @@
"use strict";
/*
Copyright (c) 2011 Elliot Shepherd
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.
*/
// https://code.google.com/p/ironchef-team21/source/browse/ironchef_team21/src/ImagePHash.java
/*
* pHash-like image hash.
* Author: Elliot Shepherd (elliot@jarofworms.com
* Based On: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
*/
function ImagePHash(size, smallerSize) {
this.size = this.size || size;
this.smallerSize = this.smallerSize || smallerSize;
initCoefficients(this.size);
}
ImagePHash.prototype.size = 32;
ImagePHash.prototype.smallerSize = 8;
ImagePHash.prototype.distance = function (s1, s2) {
var counter = 0;
for (var k = 0; k < s1.length; k++) {
if (s1[k] !== s2[k]) {
counter++;
}
}
return counter / s1.length;
}; // Returns a 'binary string' (like. 001010111011100010) which is easy to do a hamming distance on.
ImagePHash.prototype.getHash = function (img) {
/* 1. Reduce size.
* Like Average Hash, pHash starts with a small image.
* However, the image is larger than 8x8; 32x32 is a good size.
* This is really done to simplify the DCT computation and not
* because it is needed to reduce the high frequencies.
*/
img = img.clone().resize(this.size, this.size);
/* 2. Reduce color.
* The image is reduced to a grayscale just to further simplify
* the number of computations.
*/
img.grayscale();
var vals = [];
for (var x = 0; x < img.bitmap.width; x++) {
vals[x] = [];
for (var y = 0; y < img.bitmap.height; y++) {
vals[x][y] = intToRGBA(img.getPixelColor(x, y)).b;
}
}
/* 3. Compute the DCT.
* The DCT separates the image into a collection of frequencies
* and scalars. While JPEG uses an 8x8 DCT, this algorithm uses
* a 32x32 DCT.
*/
var dctVals = applyDCT(vals, this.size);
/* 4. Reduce the DCT.
* This is the magic step. While the DCT is 32x32, just keep the
* top-left 8x8. Those represent the lowest frequencies in the
* picture.
*/
/* 5. Compute the average value.
* Like the Average Hash, compute the mean DCT value (using only
* the 8x8 DCT low-frequency values and excluding the first term
* since the DC coefficient can be significantly different from
* the other values and will throw off the average).
*/
var total = 0;
for (var _x = 0; _x < this.smallerSize; _x++) {
for (var _y = 0; _y < this.smallerSize; _y++) {
total += dctVals[_x][_y];
}
}
var avg = total / (this.smallerSize * this.smallerSize);
/* 6. Further reduce the DCT.
* This is the magic step. Set the 64 hash bits to 0 or 1
* depending on whether each of the 64 DCT values is above or
* below the average value. The result doesn't tell us the
* actual low frequencies; it just tells us the very-rough
* relative scale of the frequencies to the mean. The result
* will not vary as long as the overall structure of the image
* remains the same; this can survive gamma and color histogram
* adjustments without a problem.
*/
var hash = '';
for (var _x2 = 0; _x2 < this.smallerSize; _x2++) {
for (var _y2 = 0; _y2 < this.smallerSize; _y2++) {
hash += dctVals[_x2][_y2] > avg ? '1' : '0';
}
}
return hash;
}; // DCT function stolen from http://stackoverflow.com/questions/4240490/problems-with-dct-and-idct-algorithm-in-java
function intToRGBA(i) {
var rgba = {};
rgba.r = Math.floor(i / Math.pow(256, 3));
rgba.g = Math.floor((i - rgba.r * Math.pow(256, 3)) / Math.pow(256, 2));
rgba.b = Math.floor((i - rgba.r * Math.pow(256, 3) - rgba.g * Math.pow(256, 2)) / Math.pow(256, 1));
rgba.a = Math.floor((i - rgba.r * Math.pow(256, 3) - rgba.g * Math.pow(256, 2) - rgba.b * Math.pow(256, 1)) / Math.pow(256, 0));
return rgba;
}
var c = [];
function initCoefficients(size) {
for (var i = 1; i < size; i++) {
c[i] = 1;
}
c[0] = 1 / Math.sqrt(2.0);
}
function applyDCT(f, size) {
var N = size;
var F = [];
for (var u = 0; u < N; u++) {
F[u] = [];
for (var v = 0; v < N; v++) {
var sum = 0;
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
sum += Math.cos((2 * i + 1) / (2.0 * N) * u * Math.PI) * Math.cos((2 * j + 1) / (2.0 * N) * v * Math.PI) * f[i][j];
}
}
sum *= c[u] * c[v] / 4;
F[u][v] = sum;
}
}
return F;
}
module.exports = ImagePHash;
//# sourceMappingURL=phash.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,73 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
require("core-js/modules/es.symbol");
require("core-js/modules/es.array.filter");
require("core-js/modules/es.array.for-each");
require("core-js/modules/es.object.assign");
require("core-js/modules/es.object.define-properties");
require("core-js/modules/es.object.define-property");
require("core-js/modules/es.object.get-own-property-descriptor");
require("core-js/modules/es.object.get-own-property-descriptors");
require("core-js/modules/es.object.keys");
require("core-js/modules/web.dom-collections.for-each");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/* global XMLHttpRequest */
if (process.browser || process.env.ENVIRONMENT === 'BROWSER' || typeof process.versions.electron !== 'undefined' && process.type === 'renderer' && typeof XMLHttpRequest === 'function') {
// If we run into a browser or the electron renderer process,
// use XHR method instead of Request node module.
module.exports = function (options, cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', options.url, true);
xhr.responseType = 'arraybuffer';
xhr.addEventListener('load', function () {
if (xhr.status < 400) {
try {
var data = Buffer.from(this.response);
cb(null, xhr, data);
} catch (error) {
return cb(new Error('Response is not a buffer for url ' + options.url + '. Error: ' + error.message));
}
} else {
cb(new Error('HTTP Status ' + xhr.status + ' for url ' + options.url));
}
});
xhr.addEventListener('error', function (e) {
cb(e);
});
xhr.send();
};
} else {
module.exports = function (_ref, cb) {
var options = Object.assign({}, _ref);
var p = require('phin');
p(_objectSpread({
compression: true
}, options), function (err, res) {
if (err === null) {
cb(null, res, res.body);
} else {
cb(err);
}
});
};
}
//# sourceMappingURL=request.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/request.js"],"names":["process","browser","env","ENVIRONMENT","versions","electron","type","XMLHttpRequest","module","exports","options","cb","xhr","open","url","responseType","addEventListener","status","data","Buffer","from","response","error","Error","message","e","send","p","require","compression","err","res","body"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAEA,IACEA,OAAO,CAACC,OAAR,IACAD,OAAO,CAACE,GAAR,CAAYC,WAAZ,KAA4B,SAD5B,IAEC,OAAOH,OAAO,CAACI,QAAR,CAAiBC,QAAxB,KAAqC,WAArC,IACCL,OAAO,CAACM,IAAR,KAAiB,UADlB,IAEC,OAAOC,cAAP,KAA0B,UAL9B,EAME;AACA;AACA;AAEAC,EAAAA,MAAM,CAACC,OAAP,GAAiB,UAASC,OAAT,EAAkBC,EAAlB,EAAsB;AACrC,QAAMC,GAAG,GAAG,IAAIL,cAAJ,EAAZ;AACAK,IAAAA,GAAG,CAACC,IAAJ,CAAS,KAAT,EAAgBH,OAAO,CAACI,GAAxB,EAA6B,IAA7B;AACAF,IAAAA,GAAG,CAACG,YAAJ,GAAmB,aAAnB;AACAH,IAAAA,GAAG,CAACI,gBAAJ,CAAqB,MAArB,EAA6B,YAAW;AACtC,UAAIJ,GAAG,CAACK,MAAJ,GAAa,GAAjB,EAAsB;AACpB,YAAI;AACF,cAAMC,IAAI,GAAGC,MAAM,CAACC,IAAP,CAAY,KAAKC,QAAjB,CAAb;AACAV,UAAAA,EAAE,CAAC,IAAD,EAAOC,GAAP,EAAYM,IAAZ,CAAF;AACD,SAHD,CAGE,OAAOI,KAAP,EAAc;AACd,iBAAOX,EAAE,CACP,IAAIY,KAAJ,CACE,sCACEb,OAAO,CAACI,GADV,GAEE,WAFF,GAGEQ,KAAK,CAACE,OAJV,CADO,CAAT;AAQD;AACF,OAdD,MAcO;AACLb,QAAAA,EAAE,CAAC,IAAIY,KAAJ,CAAU,iBAAiBX,GAAG,CAACK,MAArB,GAA8B,WAA9B,GAA4CP,OAAO,CAACI,GAA9D,CAAD,CAAF;AACD;AACF,KAlBD;AAmBAF,IAAAA,GAAG,CAACI,gBAAJ,CAAqB,OAArB,EAA8B,UAAAS,CAAC,EAAI;AACjCd,MAAAA,EAAE,CAACc,CAAD,CAAF;AACD,KAFD;AAGAb,IAAAA,GAAG,CAACc,IAAJ;AACD,GA3BD;AA4BD,CAtCD,MAsCO;AACLlB,EAAAA,MAAM,CAACC,OAAP,GAAiB,gBAAyBE,EAAzB,EAA6B;AAAA,QAAfD,OAAe;;AAC5C,QAAMiB,CAAC,GAAGC,OAAO,CAAC,MAAD,CAAjB;;AAEAD,IAAAA,CAAC;AAAGE,MAAAA,WAAW,EAAE;AAAhB,OAAyBnB,OAAzB,GAAoC,UAACoB,GAAD,EAAMC,GAAN,EAAc;AACjD,UAAID,GAAG,KAAK,IAAZ,EAAkB;AAChBnB,QAAAA,EAAE,CAAC,IAAD,EAAOoB,GAAP,EAAYA,GAAG,CAACC,IAAhB,CAAF;AACD,OAFD,MAEO;AACLrB,QAAAA,EAAE,CAACmB,GAAD,CAAF;AACD;AACF,KANA,CAAD;AAOD,GAVD;AAWD","sourcesContent":["/* global XMLHttpRequest */\n\nif (\n process.browser ||\n process.env.ENVIRONMENT === 'BROWSER' ||\n (typeof process.versions.electron !== 'undefined' &&\n process.type === 'renderer' &&\n typeof XMLHttpRequest === 'function')\n) {\n // If we run into a browser or the electron renderer process,\n // use XHR method instead of Request node module.\n\n module.exports = function(options, cb) {\n const xhr = new XMLHttpRequest();\n xhr.open('GET', options.url, true);\n xhr.responseType = 'arraybuffer';\n xhr.addEventListener('load', function() {\n if (xhr.status < 400) {\n try {\n const data = Buffer.from(this.response);\n cb(null, xhr, data);\n } catch (error) {\n return cb(\n new Error(\n 'Response is not a buffer for url ' +\n options.url +\n '. Error: ' +\n error.message\n )\n );\n }\n } else {\n cb(new Error('HTTP Status ' + xhr.status + ' for url ' + options.url));\n }\n });\n xhr.addEventListener('error', e => {\n cb(e);\n });\n xhr.send();\n };\n} else {\n module.exports = function({ ...options }, cb) {\n const p = require('phin');\n\n p({ compression: true, ...options }, (err, res) => {\n if (err === null) {\n cb(null, res, res.body);\n } else {\n cb(err);\n }\n });\n };\n}\n"],"file":"request.js"}

View File

@@ -0,0 +1,263 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseBitmap = parseBitmap;
exports.getBuffer = getBuffer;
exports.getBufferAsync = getBufferAsync;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
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 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;
}
/*
* Obtains image orientation from EXIF metadata.
*
* @param img {Jimp} a Jimp image object
* @returns {number} a number 1-8 representing EXIF orientation,
* in particular 1 if orientation tag is missing
*/
function getExifOrientation(img) {
return img._exif && img._exif.tags && img._exif.tags.Orientation || 1;
}
/**
* Returns a function which translates EXIF-rotated coordinates into
* non-rotated ones.
*
* Transformation reference: http://sylvana.net/jpegcrop/exif_orientation.html.
*
* @param img {Jimp} a Jimp image object
* @returns {function} transformation function for transformBitmap().
*/
function getExifOrientationTransformation(img) {
var w = img.getWidth();
var h = img.getHeight();
switch (getExifOrientation(img)) {
case 1:
// Horizontal (normal)
// does not need to be supported here
return null;
case 2:
// Mirror horizontal
return function (x, y) {
return [w - x - 1, y];
};
case 3:
// Rotate 180
return function (x, y) {
return [w - x - 1, h - y - 1];
};
case 4:
// Mirror vertical
return function (x, y) {
return [x, h - y - 1];
};
case 5:
// Mirror horizontal and rotate 270 CW
return function (x, y) {
return [y, x];
};
case 6:
// Rotate 90 CW
return function (x, y) {
return [y, h - x - 1];
};
case 7:
// Mirror horizontal and rotate 90 CW
return function (x, y) {
return [w - y - 1, h - x - 1];
};
case 8:
// Rotate 270 CW
return function (x, y) {
return [w - y - 1, x];
};
default:
return null;
}
}
/*
* Transforms bitmap in place (moves pixels around) according to given
* transformation function.
*
* @param img {Jimp} a Jimp image object, which bitmap is supposed to
* be transformed
* @param width {number} bitmap width after the transformation
* @param height {number} bitmap height after the transformation
* @param transformation {function} transformation function which defines pixel
* mapping between new and source bitmap. It takes a pair of coordinates
* in the target, and returns a respective pair of coordinates in
* the source bitmap, i.e. has following form:
* `function(new_x, new_y) { return [src_x, src_y] }`.
*/
function transformBitmap(img, width, height, transformation) {
// Underscore-prefixed values are related to the source bitmap
// Their counterparts with no prefix are related to the target bitmap
var _data = img.bitmap.data;
var _width = img.bitmap.width;
var data = Buffer.alloc(_data.length);
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
var _transformation = transformation(x, y),
_transformation2 = (0, _slicedToArray2["default"])(_transformation, 2),
_x = _transformation2[0],
_y = _transformation2[1];
var idx = width * y + x << 2;
var _idx = _width * _y + _x << 2;
var pixel = _data.readUInt32BE(_idx);
data.writeUInt32BE(pixel, idx);
}
}
img.bitmap.data = data;
img.bitmap.width = width;
img.bitmap.height = height;
}
/*
* Automagically rotates an image based on its EXIF data (if present).
* @param img {Jimp} a Jimp image object
*/
function exifRotate(img) {
if (getExifOrientation(img) < 2) return;
var transformation = getExifOrientationTransformation(img);
var swapDimensions = getExifOrientation(img) > 4;
var newWidth = swapDimensions ? img.bitmap.height : img.bitmap.width;
var newHeight = swapDimensions ? img.bitmap.width : img.bitmap.height;
transformBitmap(img, newWidth, newHeight, transformation);
} // 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

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,61 @@
"use strict";
require("core-js/modules/es.array.find");
require("core-js/modules/es.array.includes");
require("core-js/modules/es.array.slice");
require("core-js/modules/es.object.entries");
require("core-js/modules/es.regexp.exec");
require("core-js/modules/es.string.includes");
require("core-js/modules/es.string.split");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getExtension = exports.getType = exports.addType = void 0;
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('.').pop();
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

View 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","pop","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,EAA2CG,GAA3C,EAAlB;AACA,MAAMX,IAAI,GAAGL,QAAQ,CAACC,SAAD,CAArB;AAEA,SAAOI,IAAI,CAAC,CAAD,CAAX;AACD,CANM;AAQP;;;;;;;;;AAKO,IAAMY,YAAY,GAAG,SAAfA,YAAe,CAAAZ,IAAI;AAAA,SAAI,CAACN,SAAS,CAACM,IAAI,CAACa,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('.').pop();\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"}

View File

@@ -0,0 +1,34 @@
"use strict";
require("core-js/modules/es.function.bind");
require("core-js/modules/es.object.to-string");
require("core-js/modules/es.promise");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
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

View 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"}

View File

@@ -0,0 +1,214 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.srcOver = srcOver;
exports.dstOver = dstOver;
exports.multiply = multiply;
exports.screen = screen;
exports.overlay = overlay;
exports.darken = darken;
exports.lighten = lighten;
exports.hardLight = hardLight;
exports.difference = difference;
exports.exclusion = exclusion;
function srcOver(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var r = (src.r * src.a + dst.r * dst.a * (1 - src.a)) / a;
var g = (src.g * src.a + dst.g * dst.a * (1 - src.a)) / a;
var b = (src.b * src.a + dst.b * dst.a * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function dstOver(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var r = (dst.r * dst.a + src.r * src.a * (1 - dst.a)) / a;
var g = (dst.g * dst.a + src.g * src.a * (1 - dst.a)) / a;
var b = (dst.b * dst.a + src.b * src.a * (1 - dst.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function multiply(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function screen(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (sra * dst.a + dra * src.a - sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (sga * dst.a + dga * src.a - sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (sba * dst.a + dba * src.a - sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function overlay(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (2 * dra <= dst.a ? 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a) : sra * (1 + dst.a) + dra * (1 + src.a) - 2 * dra * sra - dst.a * src.a) / a;
var g = (2 * dga <= dst.a ? 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a) : sga * (1 + dst.a) + dga * (1 + src.a) - 2 * dga * sga - dst.a * src.a) / a;
var b = (2 * dba <= dst.a ? 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a) : sba * (1 + dst.a) + dba * (1 + src.a) - 2 * dba * sba - dst.a * src.a) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function darken(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (Math.min(sra * dst.a, dra * src.a) + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (Math.min(sga * dst.a, dga * src.a) + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (Math.min(sba * dst.a, dba * src.a) + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function lighten(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (Math.max(sra * dst.a, dra * src.a) + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (Math.max(sga * dst.a, dga * src.a) + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (Math.max(sba * dst.a, dba * src.a) + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function hardLight(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (2 * sra <= src.a ? 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a) : sra * (1 + dst.a) + dra * (1 + src.a) - 2 * dra * sra - dst.a * src.a) / a;
var g = (2 * sga <= src.a ? 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a) : sga * (1 + dst.a) + dga * (1 + src.a) - 2 * dga * sga - dst.a * src.a) / a;
var b = (2 * sba <= src.a ? 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a) : sba * (1 + dst.a) + dba * (1 + src.a) - 2 * dba * sba - dst.a * src.a) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function difference(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (sra + dra - 2 * Math.min(sra * dst.a, dra * src.a)) / a;
var g = (sga + dga - 2 * Math.min(sga * dst.a, dga * src.a)) / a;
var b = (sba + dba - 2 * Math.min(sba * dst.a, dba * src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
function exclusion(src, dst) {
var ops = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
src.a *= ops;
var a = dst.a + src.a - dst.a * src.a;
var sra = src.r * src.a;
var sga = src.g * src.a;
var sba = src.b * src.a;
var dra = dst.r * dst.a;
var dga = dst.g * dst.a;
var dba = dst.b * dst.a;
var r = (sra * dst.a + dra * src.a - 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
var g = (sga * dst.a + dga * src.a - 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
var b = (sba * dst.a + dba * src.a - 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return {
r: r,
g: g,
b: b,
a: a
};
}
//# sourceMappingURL=composite-modes.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,94 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = composite;
var _utils = require("@jimp/utils");
var constants = _interopRequireWildcard(require("../constants"));
var compositeModes = _interopRequireWildcard(require("./composite-modes"));
/**
* Composites a source image over to this image respecting alpha channels
* @param {Jimp} src the source Jimp instance
* @param {number} x the x position to blit the image
* @param {number} y the y position to blit the image
* @param {object} options determine what mode to use
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
function composite(src, x, y) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var cb = arguments.length > 4 ? arguments[4] : undefined;
if (typeof options === 'function') {
cb = options;
options = {};
}
if (!(src instanceof this.constructor)) {
return _utils.throwError.call(this, 'The source must be a Jimp image', cb);
}
if (typeof x !== 'number' || typeof y !== 'number') {
return _utils.throwError.call(this, 'x and y must be numbers', cb);
}
var _options = options,
mode = _options.mode,
opacitySource = _options.opacitySource,
opacityDest = _options.opacityDest;
if (!mode) {
mode = constants.BLEND_SOURCE_OVER;
}
if (typeof opacitySource !== 'number' || opacitySource < 0 || opacitySource > 1) {
opacitySource = 1.0;
}
if (typeof opacityDest !== 'number' || opacityDest < 0 || opacityDest > 1) {
opacityDest = 1.0;
}
var blendmode = compositeModes[mode]; // round input
x = Math.round(x);
y = Math.round(y);
var baseImage = this;
if (opacityDest !== 1.0) {
baseImage.opacity(opacityDest);
}
src.scanQuiet(0, 0, src.bitmap.width, src.bitmap.height, function (sx, sy, idx) {
var dstIdx = baseImage.getPixelIndex(x + sx, y + sy, constants.EDGE_CROP);
var blended = blendmode({
r: this.bitmap.data[idx + 0] / 255,
g: this.bitmap.data[idx + 1] / 255,
b: this.bitmap.data[idx + 2] / 255,
a: this.bitmap.data[idx + 3] / 255
}, {
r: baseImage.bitmap.data[dstIdx + 0] / 255,
g: baseImage.bitmap.data[dstIdx + 1] / 255,
b: baseImage.bitmap.data[dstIdx + 2] / 255,
a: baseImage.bitmap.data[dstIdx + 3] / 255
}, opacitySource);
baseImage.bitmap.data[dstIdx + 0] = this.constructor.limit255(blended.r * 255);
baseImage.bitmap.data[dstIdx + 1] = this.constructor.limit255(blended.g * 255);
baseImage.bitmap.data[dstIdx + 2] = this.constructor.limit255(blended.b * 255);
baseImage.bitmap.data[dstIdx + 3] = this.constructor.limit255(blended.a * 255);
});
if ((0, _utils.isNodePattern)(cb)) {
cb.call(this, null, this);
}
return this;
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EDGE_CROP = exports.EDGE_WRAP = exports.EDGE_EXTEND = exports.BLEND_EXCLUSION = exports.BLEND_DIFFERENCE = exports.BLEND_HARDLIGHT = exports.BLEND_LIGHTEN = exports.BLEND_DARKEN = exports.BLEND_OVERLAY = exports.BLEND_SCREEN = exports.BLEND_MULTIPLY = exports.BLEND_DESTINATION_OVER = exports.BLEND_SOURCE_OVER = exports.VERTICAL_ALIGN_BOTTOM = exports.VERTICAL_ALIGN_MIDDLE = exports.VERTICAL_ALIGN_TOP = exports.HORIZONTAL_ALIGN_RIGHT = exports.HORIZONTAL_ALIGN_CENTER = exports.HORIZONTAL_ALIGN_LEFT = exports.AUTO = void 0;
// used to auto resizing etc.
var AUTO = -1; // Align modes for cover, contain, bit masks
exports.AUTO = AUTO;
var HORIZONTAL_ALIGN_LEFT = 1;
exports.HORIZONTAL_ALIGN_LEFT = HORIZONTAL_ALIGN_LEFT;
var HORIZONTAL_ALIGN_CENTER = 2;
exports.HORIZONTAL_ALIGN_CENTER = HORIZONTAL_ALIGN_CENTER;
var HORIZONTAL_ALIGN_RIGHT = 4;
exports.HORIZONTAL_ALIGN_RIGHT = HORIZONTAL_ALIGN_RIGHT;
var VERTICAL_ALIGN_TOP = 8;
exports.VERTICAL_ALIGN_TOP = VERTICAL_ALIGN_TOP;
var VERTICAL_ALIGN_MIDDLE = 16;
exports.VERTICAL_ALIGN_MIDDLE = VERTICAL_ALIGN_MIDDLE;
var VERTICAL_ALIGN_BOTTOM = 32; // blend modes
exports.VERTICAL_ALIGN_BOTTOM = VERTICAL_ALIGN_BOTTOM;
var BLEND_SOURCE_OVER = 'srcOver';
exports.BLEND_SOURCE_OVER = BLEND_SOURCE_OVER;
var BLEND_DESTINATION_OVER = 'dstOver';
exports.BLEND_DESTINATION_OVER = BLEND_DESTINATION_OVER;
var BLEND_MULTIPLY = 'multiply';
exports.BLEND_MULTIPLY = BLEND_MULTIPLY;
var BLEND_SCREEN = 'screen';
exports.BLEND_SCREEN = BLEND_SCREEN;
var BLEND_OVERLAY = 'overlay';
exports.BLEND_OVERLAY = BLEND_OVERLAY;
var BLEND_DARKEN = 'darken';
exports.BLEND_DARKEN = BLEND_DARKEN;
var BLEND_LIGHTEN = 'lighten';
exports.BLEND_LIGHTEN = BLEND_LIGHTEN;
var BLEND_HARDLIGHT = 'hardLight';
exports.BLEND_HARDLIGHT = BLEND_HARDLIGHT;
var BLEND_DIFFERENCE = 'difference';
exports.BLEND_DIFFERENCE = BLEND_DIFFERENCE;
var BLEND_EXCLUSION = 'exclusion'; // Edge Handling
exports.BLEND_EXCLUSION = BLEND_EXCLUSION;
var EDGE_EXTEND = 1;
exports.EDGE_EXTEND = EDGE_EXTEND;
var EDGE_WRAP = 2;
exports.EDGE_WRAP = EDGE_WRAP;
var EDGE_CROP = 3;
exports.EDGE_CROP = EDGE_CROP;
//# sourceMappingURL=constants.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/constants.js"],"names":["AUTO","HORIZONTAL_ALIGN_LEFT","HORIZONTAL_ALIGN_CENTER","HORIZONTAL_ALIGN_RIGHT","VERTICAL_ALIGN_TOP","VERTICAL_ALIGN_MIDDLE","VERTICAL_ALIGN_BOTTOM","BLEND_SOURCE_OVER","BLEND_DESTINATION_OVER","BLEND_MULTIPLY","BLEND_SCREEN","BLEND_OVERLAY","BLEND_DARKEN","BLEND_LIGHTEN","BLEND_HARDLIGHT","BLEND_DIFFERENCE","BLEND_EXCLUSION","EDGE_EXTEND","EDGE_WRAP","EDGE_CROP"],"mappings":";;;;;;AAAA;AACO,IAAMA,IAAI,GAAG,CAAC,CAAd,C,CAEP;;;AACO,IAAMC,qBAAqB,GAAG,CAA9B;;AACA,IAAMC,uBAAuB,GAAG,CAAhC;;AACA,IAAMC,sBAAsB,GAAG,CAA/B;;AAEA,IAAMC,kBAAkB,GAAG,CAA3B;;AACA,IAAMC,qBAAqB,GAAG,EAA9B;;AACA,IAAMC,qBAAqB,GAAG,EAA9B,C,CAEP;;;AACO,IAAMC,iBAAiB,GAAG,SAA1B;;AACA,IAAMC,sBAAsB,GAAG,SAA/B;;AACA,IAAMC,cAAc,GAAG,UAAvB;;AACA,IAAMC,YAAY,GAAG,QAArB;;AACA,IAAMC,aAAa,GAAG,SAAtB;;AACA,IAAMC,YAAY,GAAG,QAArB;;AACA,IAAMC,aAAa,GAAG,SAAtB;;AACA,IAAMC,eAAe,GAAG,WAAxB;;AACA,IAAMC,gBAAgB,GAAG,YAAzB;;AACA,IAAMC,eAAe,GAAG,WAAxB,C,CAEP;;;AACO,IAAMC,WAAW,GAAG,CAApB;;AACA,IAAMC,SAAS,GAAG,CAAlB;;AACA,IAAMC,SAAS,GAAG,CAAlB","sourcesContent":["// used to auto resizing etc.\nexport const AUTO = -1;\n\n// Align modes for cover, contain, bit masks\nexport const HORIZONTAL_ALIGN_LEFT = 1;\nexport const HORIZONTAL_ALIGN_CENTER = 2;\nexport const HORIZONTAL_ALIGN_RIGHT = 4;\n\nexport const VERTICAL_ALIGN_TOP = 8;\nexport const VERTICAL_ALIGN_MIDDLE = 16;\nexport const VERTICAL_ALIGN_BOTTOM = 32;\n\n// blend modes\nexport const BLEND_SOURCE_OVER = 'srcOver';\nexport const BLEND_DESTINATION_OVER = 'dstOver';\nexport const BLEND_MULTIPLY = 'multiply';\nexport const BLEND_SCREEN = 'screen';\nexport const BLEND_OVERLAY = 'overlay';\nexport const BLEND_DARKEN = 'darken';\nexport const BLEND_LIGHTEN = 'lighten';\nexport const BLEND_HARDLIGHT = 'hardLight';\nexport const BLEND_DIFFERENCE = 'difference';\nexport const BLEND_EXCLUSION = 'exclusion';\n\n// Edge Handling\nexport const EDGE_EXTEND = 1;\nexport const EDGE_WRAP = 2;\nexport const EDGE_CROP = 3;\n"],"file":"constants.js"}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,173 @@
"use strict";
/*
Copyright (c) 2011 Elliot Shepherd
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.
*/
// https://code.google.com/p/ironchef-team21/source/browse/ironchef_team21/src/ImagePHash.java
/*
* pHash-like image hash.
* Author: Elliot Shepherd (elliot@jarofworms.com
* Based On: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
*/
function ImagePHash(size, smallerSize) {
this.size = this.size || size;
this.smallerSize = this.smallerSize || smallerSize;
initCoefficients(this.size);
}
ImagePHash.prototype.size = 32;
ImagePHash.prototype.smallerSize = 8;
ImagePHash.prototype.distance = function (s1, s2) {
var counter = 0;
for (var k = 0; k < s1.length; k++) {
if (s1[k] !== s2[k]) {
counter++;
}
}
return counter / s1.length;
}; // Returns a 'binary string' (like. 001010111011100010) which is easy to do a hamming distance on.
ImagePHash.prototype.getHash = function (img) {
/* 1. Reduce size.
* Like Average Hash, pHash starts with a small image.
* However, the image is larger than 8x8; 32x32 is a good size.
* This is really done to simplify the DCT computation and not
* because it is needed to reduce the high frequencies.
*/
img = img.clone().resize(this.size, this.size);
/* 2. Reduce color.
* The image is reduced to a grayscale just to further simplify
* the number of computations.
*/
img.grayscale();
var vals = [];
for (var x = 0; x < img.bitmap.width; x++) {
vals[x] = [];
for (var y = 0; y < img.bitmap.height; y++) {
vals[x][y] = intToRGBA(img.getPixelColor(x, y)).b;
}
}
/* 3. Compute the DCT.
* The DCT separates the image into a collection of frequencies
* and scalars. While JPEG uses an 8x8 DCT, this algorithm uses
* a 32x32 DCT.
*/
var dctVals = applyDCT(vals, this.size);
/* 4. Reduce the DCT.
* This is the magic step. While the DCT is 32x32, just keep the
* top-left 8x8. Those represent the lowest frequencies in the
* picture.
*/
/* 5. Compute the average value.
* Like the Average Hash, compute the mean DCT value (using only
* the 8x8 DCT low-frequency values and excluding the first term
* since the DC coefficient can be significantly different from
* the other values and will throw off the average).
*/
var total = 0;
for (var _x = 0; _x < this.smallerSize; _x++) {
for (var _y = 0; _y < this.smallerSize; _y++) {
total += dctVals[_x][_y];
}
}
var avg = total / (this.smallerSize * this.smallerSize);
/* 6. Further reduce the DCT.
* This is the magic step. Set the 64 hash bits to 0 or 1
* depending on whether each of the 64 DCT values is above or
* below the average value. The result doesn't tell us the
* actual low frequencies; it just tells us the very-rough
* relative scale of the frequencies to the mean. The result
* will not vary as long as the overall structure of the image
* remains the same; this can survive gamma and color histogram
* adjustments without a problem.
*/
var hash = '';
for (var _x2 = 0; _x2 < this.smallerSize; _x2++) {
for (var _y2 = 0; _y2 < this.smallerSize; _y2++) {
hash += dctVals[_x2][_y2] > avg ? '1' : '0';
}
}
return hash;
}; // DCT function stolen from http://stackoverflow.com/questions/4240490/problems-with-dct-and-idct-algorithm-in-java
function intToRGBA(i) {
var rgba = {};
rgba.r = Math.floor(i / Math.pow(256, 3));
rgba.g = Math.floor((i - rgba.r * Math.pow(256, 3)) / Math.pow(256, 2));
rgba.b = Math.floor((i - rgba.r * Math.pow(256, 3) - rgba.g * Math.pow(256, 2)) / Math.pow(256, 1));
rgba.a = Math.floor((i - rgba.r * Math.pow(256, 3) - rgba.g * Math.pow(256, 2) - rgba.b * Math.pow(256, 1)) / Math.pow(256, 0));
return rgba;
}
var c = [];
function initCoefficients(size) {
for (var i = 1; i < size; i++) {
c[i] = 1;
}
c[0] = 1 / Math.sqrt(2.0);
}
function applyDCT(f, size) {
var N = size;
var F = [];
for (var u = 0; u < N; u++) {
F[u] = [];
for (var v = 0; v < N; v++) {
var sum = 0;
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
sum += Math.cos((2 * i + 1) / (2.0 * N) * u * Math.PI) * Math.cos((2 * j + 1) / (2.0 * N) * v * Math.PI) * f[i][j];
}
}
sum *= c[u] * c[v] / 4;
F[u][v] = sum;
}
}
return F;
}
module.exports = ImagePHash;
//# sourceMappingURL=phash.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,55 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/* global XMLHttpRequest */
if (process.browser || process.env.ENVIRONMENT === 'BROWSER' || typeof process.versions.electron !== 'undefined' && process.type === 'renderer' && typeof XMLHttpRequest === 'function') {
// If we run into a browser or the electron renderer process,
// use XHR method instead of Request node module.
module.exports = function (options, cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', options.url, true);
xhr.responseType = 'arraybuffer';
xhr.addEventListener('load', function () {
if (xhr.status < 400) {
try {
var data = Buffer.from(this.response);
cb(null, xhr, data);
} catch (error) {
return cb(new Error('Response is not a buffer for url ' + options.url + '. Error: ' + error.message));
}
} else {
cb(new Error('HTTP Status ' + xhr.status + ' for url ' + options.url));
}
});
xhr.addEventListener('error', function (e) {
cb(e);
});
xhr.send();
};
} else {
module.exports = function (_ref, cb) {
var options = (0, _extends2["default"])({}, _ref);
var p = require('phin');
p(_objectSpread({
compression: true
}, options), function (err, res) {
if (err === null) {
cb(null, res, res.body);
} else {
cb(err);
}
});
};
}
//# sourceMappingURL=request.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/request.js"],"names":["process","browser","env","ENVIRONMENT","versions","electron","type","XMLHttpRequest","module","exports","options","cb","xhr","open","url","responseType","addEventListener","status","data","Buffer","from","response","error","Error","message","e","send","p","require","compression","err","res","body"],"mappings":";;;;;;;;;;;;AAAA;AAEA,IACEA,OAAO,CAACC,OAAR,IACAD,OAAO,CAACE,GAAR,CAAYC,WAAZ,KAA4B,SAD5B,IAEC,OAAOH,OAAO,CAACI,QAAR,CAAiBC,QAAxB,KAAqC,WAArC,IACCL,OAAO,CAACM,IAAR,KAAiB,UADlB,IAEC,OAAOC,cAAP,KAA0B,UAL9B,EAME;AACA;AACA;AAEAC,EAAAA,MAAM,CAACC,OAAP,GAAiB,UAASC,OAAT,EAAkBC,EAAlB,EAAsB;AACrC,QAAMC,GAAG,GAAG,IAAIL,cAAJ,EAAZ;AACAK,IAAAA,GAAG,CAACC,IAAJ,CAAS,KAAT,EAAgBH,OAAO,CAACI,GAAxB,EAA6B,IAA7B;AACAF,IAAAA,GAAG,CAACG,YAAJ,GAAmB,aAAnB;AACAH,IAAAA,GAAG,CAACI,gBAAJ,CAAqB,MAArB,EAA6B,YAAW;AACtC,UAAIJ,GAAG,CAACK,MAAJ,GAAa,GAAjB,EAAsB;AACpB,YAAI;AACF,cAAMC,IAAI,GAAGC,MAAM,CAACC,IAAP,CAAY,KAAKC,QAAjB,CAAb;AACAV,UAAAA,EAAE,CAAC,IAAD,EAAOC,GAAP,EAAYM,IAAZ,CAAF;AACD,SAHD,CAGE,OAAOI,KAAP,EAAc;AACd,iBAAOX,EAAE,CACP,IAAIY,KAAJ,CACE,sCACEb,OAAO,CAACI,GADV,GAEE,WAFF,GAGEQ,KAAK,CAACE,OAJV,CADO,CAAT;AAQD;AACF,OAdD,MAcO;AACLb,QAAAA,EAAE,CAAC,IAAIY,KAAJ,CAAU,iBAAiBX,GAAG,CAACK,MAArB,GAA8B,WAA9B,GAA4CP,OAAO,CAACI,GAA9D,CAAD,CAAF;AACD;AACF,KAlBD;AAmBAF,IAAAA,GAAG,CAACI,gBAAJ,CAAqB,OAArB,EAA8B,UAAAS,CAAC,EAAI;AACjCd,MAAAA,EAAE,CAACc,CAAD,CAAF;AACD,KAFD;AAGAb,IAAAA,GAAG,CAACc,IAAJ;AACD,GA3BD;AA4BD,CAtCD,MAsCO;AACLlB,EAAAA,MAAM,CAACC,OAAP,GAAiB,gBAAyBE,EAAzB,EAA6B;AAAA,QAAfD,OAAe;;AAC5C,QAAMiB,CAAC,GAAGC,OAAO,CAAC,MAAD,CAAjB;;AAEAD,IAAAA,CAAC;AAAGE,MAAAA,WAAW,EAAE;AAAhB,OAAyBnB,OAAzB,GAAoC,UAACoB,GAAD,EAAMC,GAAN,EAAc;AACjD,UAAID,GAAG,KAAK,IAAZ,EAAkB;AAChBnB,QAAAA,EAAE,CAAC,IAAD,EAAOoB,GAAP,EAAYA,GAAG,CAACC,IAAhB,CAAF;AACD,OAFD,MAEO;AACLrB,QAAAA,EAAE,CAACmB,GAAD,CAAF;AACD;AACF,KANA,CAAD;AAOD,GAVD;AAWD","sourcesContent":["/* global XMLHttpRequest */\n\nif (\n process.browser ||\n process.env.ENVIRONMENT === 'BROWSER' ||\n (typeof process.versions.electron !== 'undefined' &&\n process.type === 'renderer' &&\n typeof XMLHttpRequest === 'function')\n) {\n // If we run into a browser or the electron renderer process,\n // use XHR method instead of Request node module.\n\n module.exports = function(options, cb) {\n const xhr = new XMLHttpRequest();\n xhr.open('GET', options.url, true);\n xhr.responseType = 'arraybuffer';\n xhr.addEventListener('load', function() {\n if (xhr.status < 400) {\n try {\n const data = Buffer.from(this.response);\n cb(null, xhr, data);\n } catch (error) {\n return cb(\n new Error(\n 'Response is not a buffer for url ' +\n options.url +\n '. Error: ' +\n error.message\n )\n );\n }\n } else {\n cb(new Error('HTTP Status ' + xhr.status + ' for url ' + options.url));\n }\n });\n xhr.addEventListener('error', e => {\n cb(e);\n });\n xhr.send();\n };\n} else {\n module.exports = function({ ...options }, cb) {\n const p = require('phin');\n\n p({ compression: true, ...options }, (err, res) => {\n if (err === null) {\n cb(null, res, res.body);\n } else {\n cb(err);\n }\n });\n };\n}\n"],"file":"request.js"}

View File

@@ -0,0 +1,263 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseBitmap = parseBitmap;
exports.getBuffer = getBuffer;
exports.getBufferAsync = getBufferAsync;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
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 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;
}
/*
* Obtains image orientation from EXIF metadata.
*
* @param img {Jimp} a Jimp image object
* @returns {number} a number 1-8 representing EXIF orientation,
* in particular 1 if orientation tag is missing
*/
function getExifOrientation(img) {
return img._exif && img._exif.tags && img._exif.tags.Orientation || 1;
}
/**
* Returns a function which translates EXIF-rotated coordinates into
* non-rotated ones.
*
* Transformation reference: http://sylvana.net/jpegcrop/exif_orientation.html.
*
* @param img {Jimp} a Jimp image object
* @returns {function} transformation function for transformBitmap().
*/
function getExifOrientationTransformation(img) {
var w = img.getWidth();
var h = img.getHeight();
switch (getExifOrientation(img)) {
case 1:
// Horizontal (normal)
// does not need to be supported here
return null;
case 2:
// Mirror horizontal
return function (x, y) {
return [w - x - 1, y];
};
case 3:
// Rotate 180
return function (x, y) {
return [w - x - 1, h - y - 1];
};
case 4:
// Mirror vertical
return function (x, y) {
return [x, h - y - 1];
};
case 5:
// Mirror horizontal and rotate 270 CW
return function (x, y) {
return [y, x];
};
case 6:
// Rotate 90 CW
return function (x, y) {
return [y, h - x - 1];
};
case 7:
// Mirror horizontal and rotate 90 CW
return function (x, y) {
return [w - y - 1, h - x - 1];
};
case 8:
// Rotate 270 CW
return function (x, y) {
return [w - y - 1, x];
};
default:
return null;
}
}
/*
* Transforms bitmap in place (moves pixels around) according to given
* transformation function.
*
* @param img {Jimp} a Jimp image object, which bitmap is supposed to
* be transformed
* @param width {number} bitmap width after the transformation
* @param height {number} bitmap height after the transformation
* @param transformation {function} transformation function which defines pixel
* mapping between new and source bitmap. It takes a pair of coordinates
* in the target, and returns a respective pair of coordinates in
* the source bitmap, i.e. has following form:
* `function(new_x, new_y) { return [src_x, src_y] }`.
*/
function transformBitmap(img, width, height, transformation) {
// Underscore-prefixed values are related to the source bitmap
// Their counterparts with no prefix are related to the target bitmap
var _data = img.bitmap.data;
var _width = img.bitmap.width;
var data = Buffer.alloc(_data.length);
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
var _transformation = transformation(x, y),
_transformation2 = (0, _slicedToArray2["default"])(_transformation, 2),
_x = _transformation2[0],
_y = _transformation2[1];
var idx = width * y + x << 2;
var _idx = _width * _y + _x << 2;
var pixel = _data.readUInt32BE(_idx);
data.writeUInt32BE(pixel, idx);
}
}
img.bitmap.data = data;
img.bitmap.width = width;
img.bitmap.height = height;
}
/*
* Automagically rotates an image based on its EXIF data (if present).
* @param img {Jimp} a Jimp image object
*/
function exifRotate(img) {
if (getExifOrientation(img) < 2) return;
var transformation = getExifOrientationTransformation(img);
var swapDimensions = getExifOrientation(img) > 4;
var newWidth = swapDimensions ? img.bitmap.height : img.bitmap.width;
var newHeight = swapDimensions ? img.bitmap.width : img.bitmap.height;
transformBitmap(img, newWidth, newHeight, transformation);
} // 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

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getExtension = exports.getType = exports.addType = void 0;
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('.').pop();
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

View 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","pop","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,EAA2CG,GAA3C,EAAlB;AACA,MAAMX,IAAI,GAAGL,QAAQ,CAACC,SAAD,CAArB;AAEA,SAAOI,IAAI,CAAC,CAAD,CAAX;AACD,CANM;AAQP;;;;;;;;;AAKO,IAAMY,YAAY,GAAG,SAAfA,YAAe,CAAAZ,IAAI;AAAA,SAAI,CAACN,SAAS,CAACM,IAAI,CAACa,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('.').pop();\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"}

View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
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;
//# sourceMappingURL=promisify.js.map

View 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"}

View File

@@ -0,0 +1,58 @@
{
"name": "@jimp/core",
"version": "0.10.3",
"description": "Jimp core",
"main": "dist/index.js",
"module": "es/index.js",
"types": "types/index.d.ts",
"files": [
"dist",
"es",
"index.d.ts",
"fonts",
"types"
],
"repository": {
"type": "git",
"url": "https://github.com/oliver-moran/jimp.git"
},
"bugs": {
"url": "https://github.com/oliver-moran/jimp/issues"
},
"scripts": {
"test": "cross-env BABEL_ENV=test mocha --require @babel/register test/**/*.js",
"test:watch": "npm run test -- --reporter min --watch",
"test:coverage": "nyc npm run test",
"build": "npm run build:node:production && npm run build:module",
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
"build:debug": "npm run build:node:debug",
"build:module": "cross-env BABEL_ENV=module babel src -d es --source-maps --config-file ../../babel.config.js",
"build:node": "babel src -d dist --source-maps --config-file ../../babel.config.js",
"build:node:debug": "cross-env BABEL_ENV=development npm run build:node",
"build:node:production": "cross-env BABEL_ENV=production npm run build:node"
},
"author": "Oliver Moran <oliver.moran@gmail.com>",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.7.2",
"@jimp/utils": "^0.10.3",
"any-base": "^1.1.0",
"buffer": "^5.2.0",
"core-js": "^3.4.1",
"exif-parser": "^0.1.12",
"file-type": "^9.0.0",
"load-bmfont": "^1.3.1",
"mkdirp": "^0.5.1",
"phin": "^2.9.1",
"pixelmatch": "^4.0.2",
"tinycolor2": "^1.4.1"
},
"devDependencies": {
"should": "^13.2.3"
},
"xo": false,
"publishConfig": {
"access": "public"
},
"gitHead": "37197106eae5c26231018dfdc0254422f6b43927"
}

View File

@@ -0,0 +1,91 @@
import {Jimp} from './jimp';
export interface Image {
bitmap: Bitmap;
}
export type DecoderFn = (data: Buffer) => Bitmap;
export type EncoderFn<ImageType extends Image = Image> = (
image: ImageType
) => Buffer;
export type GenericCallback<T, U = any, TThis = any> = (
this: TThis,
err: Error | null,
value: T
) => U;
/**
* `jimp` must be defined otherwise `this` will not apply properly
* for custom configurations where plugins and types are needed
*/
export type ImageCallback<jimp = Jimp> = (
this: jimp,
err: Error | null,
value: jimp,
coords: {
x: number;
y: number;
}
) => any;
type BlendMode = {
mode: string;
opacitySource: number;
opacityDest: number;
};
type ChangeName = 'background' | 'scan' | 'crop';
type ListenableName =
| 'any'
| 'initialized'
| 'before-change'
| 'changed'
| 'before-clone'
| 'cloned'
| ChangeName;
type ListenerData<T extends ListenableName> = T extends 'any'
? any
: T extends ChangeName
? {
eventName: 'before-change' | 'changed';
methodName: T;
[key: string]: any;
}
: {
eventName: T;
methodName: T extends 'initialized'
? 'constructor'
: T extends 'before-change' | 'changed'
? ChangeName
: T extends 'before-clone' | 'cloned' ? 'clone' : any;
};
type URLOptions = {
url: string;
compression?: boolean;
headers: {
[key: string]: any;
};
};
export interface Bitmap {
data: Buffer;
width: number;
height: number;
}
export interface RGB {
r: number;
g: number;
b: number;
}
export interface RGBA {
r: number;
g: number;
b: number;
a: number;
}

View File

@@ -0,0 +1,17 @@
import {Jimp} from './jimp';
export function addConstants(
constants: [string, string | number],
jimpInstance?: Jimp
): void;
export function addJimpMethods(
methods: [string, Function],
jimpInstance?: Jimp
): void;
export function jimpEvMethod(
methodName: string,
evName: string,
method: Function
): void;
export function jimpEvChange(methodName: string, method: Function): void;
export function addType(mime: string, extensions: string[]): void;

View File

@@ -0,0 +1,9 @@
export * from './etc';
export * from './functions';
export * from './plugins';
export * from './utils';
import {Jimp, JimpConstructors} from './jimp';
export { Jimp, JimpConstructors };
declare const defaultExp: Jimp;
export default defaultExp;

View File

@@ -0,0 +1,218 @@
import {
Bitmap,
ImageCallback,
URLOptions,
ListenableName,
ListenerData,
GenericCallback,
BlendMode,
RGBA,
RGB
} from './etc';
interface DiffReturn<This> {
percent: number;
image: This;
}
interface ScanIteratorReturn<This> {
x: number;
y: number;
idx: number;
image: This;
}
export interface JimpConstructors {
prototype: Jimp;
// Constants
AUTO: -1;
// blend modes
BLEND_SOURCE_OVER: string;
BLEND_DESTINATION_OVER: string;
BLEND_MULTIPLY: string;
BLEND_SCREEN: string;
BLEND_OVERLAY: string;
BLEND_DARKEN: string;
BLEND_LIGHTEN: string;
BLEND_HARDLIGHT: string;
BLEND_DIFFERENCE: string;
BLEND_EXCLUSION: string;
// Align modes for cover, contain, bit masks
HORIZONTAL_ALIGN_LEFT: 1;
HORIZONTAL_ALIGN_CENTER: 2;
HORIZONTAL_ALIGN_RIGHT: 4;
VERTICAL_ALIGN_TOP: 8;
VERTICAL_ALIGN_MIDDLE: 16;
VERTICAL_ALIGN_BOTTOM: 32;
// Edge Handling
EDGE_EXTEND: 1;
EDGE_WRAP: 2;
EDGE_CROP: 3;
// Constructors
new(path: string, cb?: ImageCallback<this['prototype']>): this['prototype'];
new(urlOptions: URLOptions, cb?: ImageCallback<this['prototype']>): this['prototype'];
new(image: Jimp, cb?: ImageCallback<this['prototype']>): this['prototype'];
new(data: Buffer, cb?: ImageCallback<this['prototype']>): this['prototype'];
new(data: Bitmap, cb?: ImageCallback<this['prototype']>): this['prototype'];
new(w: number, h: number, cb?: ImageCallback<this['prototype']>): this['prototype'];
new(
w: number,
h: number,
background?: number | string,
cb?: ImageCallback<this['prototype']>
): this['prototype'];
// For custom constructors when using Jimp.appendConstructorOption
new(...args: any[]): this['prototype'];
// Functions
/**
* I'd like to make `Args` generic and used in `run` and `test` but alas,
* it's not possible RN:
* https://github.com/microsoft/TypeScript/issues/26113
*/
appendConstructorOption<Args extends any[], J extends Jimp = this['prototype']>(
name: string,
test: (...args: any[]) => boolean,
run: (
this: J,
resolve: (jimp?: J) => any,
reject: (reason: Error) => any,
...args: any[]
) => any
): void;
read(path: string, cb?: ImageCallback<this['prototype']>): Promise<this['prototype']>;
read(image: Jimp, cb?: ImageCallback<this['prototype']>): Promise<this['prototype']>;
read(data: Buffer, cb?: ImageCallback<this['prototype']>): Promise<this['prototype']>;
read(
w: number,
h: number,
background?: number | string,
cb?: ImageCallback<this['prototype']>
): Promise<this['prototype']>;
create(path: string): Promise<this['prototype']>;
create(image: Jimp): Promise<this['prototype']>;
create(data: Buffer): Promise<this['prototype']>;
create(w: number, h: number, background?: number | string): Promise<this['prototype']>;
rgbaToInt(
r: number,
g: number,
b: number,
a: number,
cb: GenericCallback<number, any, this['prototype']>
): number;
intToRGBA(i: number, cb?: GenericCallback<RGBA>): RGBA;
cssColorToHex(cssColor: string): number;
limit255(n: number): number;
diff(img1: Jimp, img2: Jimp, threshold?: number): DiffReturn<this['prototype']>;
distance(img1: Jimp, img2: Jimp): number;
compareHashes(hash1: string, hash2: string): number;
colorDiff(rgba1: RGB, rgba2: RGB): number;
colorDiff(rgba1: RGBA, rgba2: RGBA): number;
}
export interface Jimp {
// Properties
bitmap: Bitmap;
_rgba: boolean;
_background: number;
_originalMime: string;
// Methods
on<T extends ListenableName>(
event: T,
cb: (data: ListenerData<T>) => any
): any;
parseBitmap(
data: Buffer,
path: string | null | undefined,
cb?: ImageCallback<this>
): void;
hasAlpha(): boolean;
getHeight(): number;
getWidth(): number;
inspect(): string;
toString(): string;
getMIME(): string;
getExtension(): string;
distanceFromHash(hash: string): number;
write(path: string, cb?: ImageCallback<this>): this;
writeAsync(path: string): Promise<this>;
rgba(bool: boolean, cb?: ImageCallback<this>): this;
getBase64(mime: string, cb: GenericCallback<string, any, this>): this;
getBase64Async(mime: string): Promise<string>;
hash(cb?: GenericCallback<string, any, this>): string;
hash(
base: number | null | undefined,
cb?: GenericCallback<string, any, this>
): string;
getBuffer(mime: string, cb: GenericCallback<Buffer>): this;
getBufferAsync(mime: string): Promise<Buffer>;
getPixelIndex(
x: number,
y: number,
cb?: GenericCallback<number, any, this>
): number;
getPixelIndex(
x: number,
y: number,
edgeHandling: string,
cb?: GenericCallback<number, any, this>
): number;
getPixelColor(
x: number,
y: number,
cb?: GenericCallback<number, any, this>
): number;
getPixelColour(
x: number,
y: number,
cb?: GenericCallback<number, any, this>
): number;
setPixelColor(
hex: number,
x: number,
y: number,
cb?: ImageCallback<this>
): this;
setPixelColour(
hex: number,
x: number,
y: number,
cb?: ImageCallback<this>
): this;
clone(cb?: ImageCallback<this>): this;
cloneQuiet(cb?: ImageCallback<this>): this;
background(hex: number, cb?: ImageCallback<this>): this;
backgroundQuiet(hex: number, cb?: ImageCallback<this>): this;
scan(
x: number,
y: number,
w: number,
h: number,
f: (this: this, x: number, y: number, idx: number) => any,
cb?: ImageCallback<this>
): this;
scanQuiet(
x: number,
y: number,
w: number,
h: number,
f: (this: this, x: number, y: number, idx: number) => any,
cb?: ImageCallback<this>
): this;
scanIterator(
x: number,
y: number,
w: number,
h: number
): IterableIterator<ScanIteratorReturn<this>>;
// Effect methods
composite(
src: Jimp,
x: number,
y: number,
options?: BlendMode,
cb?: ImageCallback<this>
): this;
}

View File

@@ -0,0 +1,57 @@
/**
* These files pertain to the typings of plugins or types
*
* They're not meant as utils to decode types, but rather
* the type definitons themsleves for plugins and types of various kinds
*/
import {
Image,
EncoderFn,
DecoderFn
} from './etc';
import {
Omit
} from './utils';
export type IllformedPlugin = Omit<any, 'class' | 'constants'> & {
class?: never;
constants?: never;
}
export interface WellFormedPlugin<ImageType extends Image = Image> {
mime?: {
[MIME_TYPE: string]: string[];
};
hasAlpha?: {
[MIME_SPECIAL: string]: boolean;
};
constants?: {
// Contants to assign to the Jimp instance
[MIME_SPECIAL: string]: any;
};
decoders?: {
[MIME_TYPE: string]: DecoderFn;
};
encoders?: {
// Jimp Image
[MIME_TYPE: string]: EncoderFn<ImageType>;
};
// Extend the Jimp class with the following constants, etc
class?: any;
}
type ClassOrConstantPlugin<T extends Image> = WellFormedPlugin<T> &
(
| Required<Pick<WellFormedPlugin<T>, 'class'>>
| Required<Pick<WellFormedPlugin<T>, 'constants'>>
);
// A Jimp type requires mime, but not class
export type JimpType<T extends Image = Image> = WellFormedPlugin<T> &
Required<Pick<WellFormedPlugin<T>, 'mime'>>;
// Jimp plugin either MUST have class OR constant or be illformed
export type JimpPlugin<T extends Image = Image> =
| ClassOrConstantPlugin<T>
| IllformedPlugin;

View File

@@ -0,0 +1,104 @@
import {
JimpType,
JimpPlugin,
} from './plugins';
// This is required as providing type arrays gives a union of all the generic
// types in the array rather than an intersection
export type UnionToIntersection<U> =
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
/**
* The values to be extracted from a WellFormedPlugin to put onto the Jimp instance
* Left loose as "any" in order to enable the GetPluginVal to work properly
*/
export type WellFormedValues<T extends any> =
(T extends {class: infer Class} ? Class : {});
/**
* The constants to be extracted from a WellFormedPlugin to put onto the Jimp instance
* Left loose as "any" in order to enable the GetPluginConstants to work properly
*/
export type WellFormedConstants<T extends any> =
(T extends {constants: infer Constants} ? Constants : {});
// Util type for the functions that deal with `@jimp/custom`
// Must accept any or no props thanks to typing of the `plugins` intersected function
export type FunctionRet<T> = Array<(...props: any[] | never) => T>;
/**
* This conditional cannot be flipped. TS assumes that Q is `WellFormed` even
* it does not have the `class` or `constant` props. As a result, it will end
* up `undefined`. Because we're always extending `IllformedPlugin` on the
* plugins, this should work fine
*/
export type GetPluginVal<Q> = Q extends Required<{class: any}> | Required<{constants: any}>
? WellFormedValues<Q>
: Q;
export type GetPluginConst<Q> = Q extends Required<{class: any}> | Required<{constants: any}>
? WellFormedConstants<Q>
: {};
export type GetPluginDecoders<Q> = Q extends Required<{class: any}> | Required<{constants: any}>
? Q extends {decoders: infer Decoders} ? Decoders : {} : {};
export type GetPluginEncoders<Q> = Q extends Required<{class: any}> | Required<{constants: any}>
? Q extends {encoders: infer Encoders} ? Encoders : {} : {};
type GetPluginFuncArrValues<PluginFuncArr> =
// Given an array of types infer `Q` (Q should be the type value)
PluginFuncArr extends ReadonlyArray<infer F> ? F extends () => infer Q
? // Get the plugin value, may be ill-formed or well-formed
GetPluginVal<Q>
: // This should never be reached
undefined : undefined;
/**
* A helper type to get the values to be intersected with `Jimp` to give
* the proper typing given an array of functions for plugins and types
*/
export type GetIntersectionFromPlugins<
PluginFuncArr extends FunctionRet<JimpPlugin | JimpType>
> = UnionToIntersection<Exclude<GetPluginFuncArrValues<PluginFuncArr>, undefined>>;
type GetPluginFuncArrConsts<PluginFuncArr> =
// Given an array of types infer `Q` (Q should be the type value)
PluginFuncArr extends ReadonlyArray<infer F> ? F extends () => infer Q
? // Get the plugin constants, may be ill-formed or well-formed
GetPluginConst<Q>
: // This should never be reached
undefined : undefined;
type GetPluginFuncArrEncoders<PluginFuncArr> =
// Given an array of types infer `Q` (Q should be the type value)
PluginFuncArr extends ReadonlyArray<infer F> ? F extends () => infer Q
? // Get the plugin encoders, may be ill-formed or well-formed
GetPluginEncoders<Q>
: // This should never be reached
undefined : undefined;
type GetPluginFuncArrDecoders<PluginFuncArr> =
// Given an array of types infer `Q` (Q should be the type value)
PluginFuncArr extends ReadonlyArray<infer F> ? F extends () => infer Q
? // Get the plugin decoders, may be ill-formed or well-formed
GetPluginDecoders<Q>
: // This should never be reached
undefined : undefined;
/**
* A helper type to get the statics to be intersected with `Jimp` to give
* the proper typing given an array of functions for plugins and types
*/
export type GetIntersectionFromPluginsStatics<
PluginFuncArr extends FunctionRet<JimpPlugin | JimpType>
> = UnionToIntersection<GetPluginFuncArrConsts<PluginFuncArr>> & {
encoders: UnionToIntersection<GetPluginFuncArrEncoders<PluginFuncArr>>;
decoders: UnionToIntersection<GetPluginFuncArrDecoders<PluginFuncArr>>;
};
/**
* While this was added to TS 3.5, in order to support down to TS 2.8, we need
* to export this and use it in sub-packges that utilize it
*/
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;

View File

@@ -0,0 +1,35 @@
# v0.10.0 (Mon Mar 30 2020)
#### 🚀 Enhancement
- Properly split constructor and instance types [#867](https://github.com/oliver-moran/jimp/pull/867) ([@forivall](https://github.com/forivall))
#### Authors: 1
- Emily Marigold Klassen ([@forivall](https://github.com/forivall))
---
# v0.9.6 (Wed Mar 18 2020)
#### 🏠 Internal
- Fix TypeScript error on 'next' [#858](https://github.com/oliver-moran/jimp/pull/858) ([@crutchcorn](https://github.com/crutchcorn))
#### Authors: 1
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))
---
# v0.9.3 (Tue Nov 26 2019)
#### 🐛 Bug Fix
- `@jimp/cli`, `@jimp/core`, `@jimp/custom`, `jimp`, `@jimp/plugin-blit`, `@jimp/plugin-blur`, `@jimp/plugin-circle`, `@jimp/plugin-color`, `@jimp/plugin-contain`, `@jimp/plugin-cover`, `@jimp/plugin-crop`, `@jimp/plugin-displace`, `@jimp/plugin-dither`, `@jimp/plugin-fisheye`, `@jimp/plugin-flip`, `@jimp/plugin-gaussian`, `@jimp/plugin-invert`, `@jimp/plugin-mask`, `@jimp/plugin-normalize`, `@jimp/plugin-print`, `@jimp/plugin-resize`, `@jimp/plugin-rotate`, `@jimp/plugin-scale`, `@jimp/plugin-shadow`, `@jimp/plugin-threshold`, `@jimp/plugins`, `@jimp/test-utils`, `@jimp/bmp`, `@jimp/gif`, `@jimp/jpeg`, `@jimp/png`, `@jimp/tiff`, `@jimp/types`, `@jimp/utils`
- Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 2
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Oliver Moran
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.

View File

@@ -0,0 +1,196 @@
<div align="center">
<img width="200" height="200"
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
<h1>@jimp/custom</h1>
<p>Configure jimp with types and plugins.</p>
</div>
## Useful Defaults
The following wil configure a `jimp` instance with the same functionality as the main `jimp` package.
```js
import configure from '@jimp/custom';
// all of jimp's default types
import types from '@jimp/types';
// all of jimp's default types
import plugins from '@jimp/plugins';
configure({
types: [types],
plugins: [plugins]
});
```
## Available Methods
### configure
Takes a Jimp configuration and applies it to `@jimp/core`.
Sample Jimp configuration:
```js
import types from '@jimp/types';
import bmp from '@jimp/bmp';
import jpeg from '@jimp/types';
...
configure({
types: [types]
})
// or
configure({
types: [bmp, jpeg, ...]
})
```
#### Extending Jimp Further
You can use configure to add more types and plugins to a jimp multiple times.
```js
let jimp = configure({
types: [bmp]
});
jimp = configure(
{
types: [jpeg]
},
jimp
);
```
## Type Definition
To define a new Jimp image type write a function the takes the current Jimp configuration. In this function you can extend Jimp's internal data structures.
This function must return an object whose key is the mime type and value is an array of valid file extensions.
```js
const special = require('special-js');
const MIME_TYPE = 'image/special';
export default () => ({
mime: {[MIME_TYPE], ['spec', 'special']},
constants: {
MIME_SPECIAL: MIME_TYPE
},
decoders: {
[MIME_TYPE]: data => special.decode(data)
},
encoders: {
[MIME_TYPE]: image => special.encode(image.bitmap)
}
});
```
### Constants
A jimp image type can expose as many constants as it wants. Each jimp type is required to expose a mime type.
```js
constants: {
MIME_SPECIAL: MIME_TYPE
},
```
### hasAlpha
A image type can define whether it supports an alpha channel.
```js
hasAlpha: {
MIME_SPECIAL: true
},
```
### Decoder
A function that when supplied with a buffer should return a bitmap with height and width.
```js
decoders: {
[MIME_TYPE]: data => special.decode(data)
},
```
### Encoder
A function that when supplied with a Jimp image should return an encoded buffer.
```js
encoders: {
[MIME_TYPE]: image => special.encode(image.bitmap)
}
```
### Class
Add class properties and function to the Jimp constructor.
```js
class: {
_quality: 100,
quality: function(n, cb) {
if (typeof n !== 'number') {
return throwError.call(this, 'n must be a number', cb);
}
if (n < 0 || n > 100) {
return throwError.call(this, 'n must be a number 0 - 100', cb);
}
this._quality = Math.round(n);
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
};
```
## Plugin Definition
Defining a plugin has access to all the same things in the type definition. Mainly plugins use just the `constants` and `class` config options.
Below is the `invert` plugin. If a plugin doesn return an object with `constants` and `class`, all keys are treated as class functions.
```js
import { isNodePattern } from '@jimp/utils';
/**
* Inverts the image
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
export default () => ({
invert(cb) {
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
x,
y,
idx
) {
this.bitmap.data[idx] = 255 - this.bitmap.data[idx];
this.bitmap.data[idx + 1] = 255 - this.bitmap.data[idx + 1];
this.bitmap.data[idx + 2] = 255 - this.bitmap.data[idx + 2];
});
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
});
```

View File

@@ -0,0 +1,111 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
require("core-js/modules/es.symbol");
require("core-js/modules/es.array.filter");
require("core-js/modules/es.array.for-each");
require("core-js/modules/es.array.is-array");
require("core-js/modules/es.object.define-properties");
require("core-js/modules/es.object.define-property");
require("core-js/modules/es.object.entries");
require("core-js/modules/es.object.get-own-property-descriptor");
require("core-js/modules/es.object.get-own-property-descriptors");
require("core-js/modules/es.object.keys");
require("core-js/modules/web.dom-collections.for-each");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = configure;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _core = _interopRequireWildcard(require("@jimp/core"));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function configure(configuration) {
var jimpInstance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _core["default"];
var jimpConfig = {
hasAlpha: {},
encoders: {},
decoders: {},
"class": {},
constants: {}
};
function addToConfig(newConfig) {
Object.entries(newConfig).forEach(function (_ref) {
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
key = _ref2[0],
value = _ref2[1];
jimpConfig[key] = _objectSpread({}, jimpConfig[key], {}, value);
});
}
function addImageType(typeModule) {
var type = typeModule();
if (Array.isArray(type.mime)) {
_core.addType.apply(void 0, (0, _toConsumableArray2["default"])(type.mime));
} else {
Object.entries(type.mime).forEach(function (mimeType) {
return _core.addType.apply(void 0, (0, _toConsumableArray2["default"])(mimeType));
});
}
delete type.mime;
addToConfig(type);
}
function addPlugin(pluginModule) {
var plugin = pluginModule(_core.jimpEvChange) || {};
if (!plugin["class"] && !plugin.constants) {
// Default to class function
addToConfig({
"class": plugin
});
} else {
addToConfig(plugin);
}
}
if (configuration.types) {
configuration.types.forEach(addImageType);
jimpInstance.decoders = _objectSpread({}, jimpInstance.decoders, {}, jimpConfig.decoders);
jimpInstance.encoders = _objectSpread({}, jimpInstance.encoders, {}, jimpConfig.encoders);
jimpInstance.hasAlpha = _objectSpread({}, jimpInstance.hasAlpha, {}, jimpConfig.hasAlpha);
}
if (configuration.plugins) {
configuration.plugins.forEach(addPlugin);
}
(0, _core.addJimpMethods)(jimpConfig["class"], jimpInstance);
(0, _core.addConstants)(jimpConfig.constants, jimpInstance);
return _core["default"];
}
module.exports = exports.default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":["configure","configuration","jimpInstance","Jimp","jimpConfig","hasAlpha","encoders","decoders","constants","addToConfig","newConfig","Object","entries","forEach","key","value","addImageType","typeModule","type","Array","isArray","mime","addType","mimeType","addPlugin","pluginModule","plugin","jimpEvChange","types","plugins"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAOe,SAASA,SAAT,CAAmBC,aAAnB,EAAuD;AAAA,MAArBC,YAAqB,uEAANC,gBAAM;AACpE,MAAMC,UAAU,GAAG;AACjBC,IAAAA,QAAQ,EAAE,EADO;AAEjBC,IAAAA,QAAQ,EAAE,EAFO;AAGjBC,IAAAA,QAAQ,EAAE,EAHO;AAIjB,aAAO,EAJU;AAKjBC,IAAAA,SAAS,EAAE;AALM,GAAnB;;AAQA,WAASC,WAAT,CAAqBC,SAArB,EAAgC;AAC9BC,IAAAA,MAAM,CAACC,OAAP,CAAeF,SAAf,EAA0BG,OAA1B,CAAkC,gBAAkB;AAAA;AAAA,UAAhBC,GAAgB;AAAA,UAAXC,KAAW;;AAClDX,MAAAA,UAAU,CAACU,GAAD,CAAV,qBACKV,UAAU,CAACU,GAAD,CADf,MAEKC,KAFL;AAID,KALD;AAMD;;AAED,WAASC,YAAT,CAAsBC,UAAtB,EAAkC;AAChC,QAAMC,IAAI,GAAGD,UAAU,EAAvB;;AAEA,QAAIE,KAAK,CAACC,OAAN,CAAcF,IAAI,CAACG,IAAnB,CAAJ,EAA8B;AAC5BC,sEAAWJ,IAAI,CAACG,IAAhB;AACD,KAFD,MAEO;AACLV,MAAAA,MAAM,CAACC,OAAP,CAAeM,IAAI,CAACG,IAApB,EAA0BR,OAA1B,CAAkC,UAAAU,QAAQ;AAAA,eAAID,gEAAWC,QAAX,EAAJ;AAAA,OAA1C;AACD;;AAED,WAAOL,IAAI,CAACG,IAAZ;AACAZ,IAAAA,WAAW,CAACS,IAAD,CAAX;AACD;;AAED,WAASM,SAAT,CAAmBC,YAAnB,EAAiC;AAC/B,QAAMC,MAAM,GAAGD,YAAY,CAACE,kBAAD,CAAZ,IAA8B,EAA7C;;AACA,QAAI,CAACD,MAAM,SAAP,IAAiB,CAACA,MAAM,CAAClB,SAA7B,EAAwC;AACtC;AACAC,MAAAA,WAAW,CAAC;AAAE,iBAAOiB;AAAT,OAAD,CAAX;AACD,KAHD,MAGO;AACLjB,MAAAA,WAAW,CAACiB,MAAD,CAAX;AACD;AACF;;AAED,MAAIzB,aAAa,CAAC2B,KAAlB,EAAyB;AACvB3B,IAAAA,aAAa,CAAC2B,KAAd,CAAoBf,OAApB,CAA4BG,YAA5B;AAEAd,IAAAA,YAAY,CAACK,QAAb,qBACKL,YAAY,CAACK,QADlB,MAEKH,UAAU,CAACG,QAFhB;AAIAL,IAAAA,YAAY,CAACI,QAAb,qBACKJ,YAAY,CAACI,QADlB,MAEKF,UAAU,CAACE,QAFhB;AAIAJ,IAAAA,YAAY,CAACG,QAAb,qBACKH,YAAY,CAACG,QADlB,MAEKD,UAAU,CAACC,QAFhB;AAID;;AAED,MAAIJ,aAAa,CAAC4B,OAAlB,EAA2B;AACzB5B,IAAAA,aAAa,CAAC4B,OAAd,CAAsBhB,OAAtB,CAA8BW,SAA9B;AACD;;AAED,4BAAepB,UAAU,SAAzB,EAAiCF,YAAjC;AACA,0BAAaE,UAAU,CAACI,SAAxB,EAAmCN,YAAnC;AAEA,SAAOC,gBAAP;AACD","sourcesContent":["import Jimp, {\n addType,\n addJimpMethods,\n addConstants,\n jimpEvChange\n} from '@jimp/core';\n\nexport default function configure(configuration, jimpInstance = Jimp) {\n const jimpConfig = {\n hasAlpha: {},\n encoders: {},\n decoders: {},\n class: {},\n constants: {}\n };\n\n function addToConfig(newConfig) {\n Object.entries(newConfig).forEach(([key, value]) => {\n jimpConfig[key] = {\n ...jimpConfig[key],\n ...value\n };\n });\n }\n\n function addImageType(typeModule) {\n const type = typeModule();\n\n if (Array.isArray(type.mime)) {\n addType(...type.mime);\n } else {\n Object.entries(type.mime).forEach(mimeType => addType(...mimeType));\n }\n\n delete type.mime;\n addToConfig(type);\n }\n\n function addPlugin(pluginModule) {\n const plugin = pluginModule(jimpEvChange) || {};\n if (!plugin.class && !plugin.constants) {\n // Default to class function\n addToConfig({ class: plugin });\n } else {\n addToConfig(plugin);\n }\n }\n\n if (configuration.types) {\n configuration.types.forEach(addImageType);\n\n jimpInstance.decoders = {\n ...jimpInstance.decoders,\n ...jimpConfig.decoders\n };\n jimpInstance.encoders = {\n ...jimpInstance.encoders,\n ...jimpConfig.encoders\n };\n jimpInstance.hasAlpha = {\n ...jimpInstance.hasAlpha,\n ...jimpConfig.hasAlpha\n };\n }\n\n if (configuration.plugins) {\n configuration.plugins.forEach(addPlugin);\n }\n\n addJimpMethods(jimpConfig.class, jimpInstance);\n addConstants(jimpConfig.constants, jimpInstance);\n\n return Jimp;\n}\n"],"file":"index.js"}

View File

@@ -0,0 +1,87 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = configure;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _core = _interopRequireWildcard(require("@jimp/core"));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function configure(configuration) {
var jimpInstance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _core["default"];
var jimpConfig = {
hasAlpha: {},
encoders: {},
decoders: {},
"class": {},
constants: {}
};
function addToConfig(newConfig) {
Object.entries(newConfig).forEach(function (_ref) {
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
key = _ref2[0],
value = _ref2[1];
jimpConfig[key] = _objectSpread({}, jimpConfig[key], {}, value);
});
}
function addImageType(typeModule) {
var type = typeModule();
if (Array.isArray(type.mime)) {
_core.addType.apply(void 0, (0, _toConsumableArray2["default"])(type.mime));
} else {
Object.entries(type.mime).forEach(function (mimeType) {
return _core.addType.apply(void 0, (0, _toConsumableArray2["default"])(mimeType));
});
}
delete type.mime;
addToConfig(type);
}
function addPlugin(pluginModule) {
var plugin = pluginModule(_core.jimpEvChange) || {};
if (!plugin["class"] && !plugin.constants) {
// Default to class function
addToConfig({
"class": plugin
});
} else {
addToConfig(plugin);
}
}
if (configuration.types) {
configuration.types.forEach(addImageType);
jimpInstance.decoders = _objectSpread({}, jimpInstance.decoders, {}, jimpConfig.decoders);
jimpInstance.encoders = _objectSpread({}, jimpInstance.encoders, {}, jimpConfig.encoders);
jimpInstance.hasAlpha = _objectSpread({}, jimpInstance.hasAlpha, {}, jimpConfig.hasAlpha);
}
if (configuration.plugins) {
configuration.plugins.forEach(addPlugin);
}
(0, _core.addJimpMethods)(jimpConfig["class"], jimpInstance);
(0, _core.addConstants)(jimpConfig.constants, jimpInstance);
return _core["default"];
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":["configure","configuration","jimpInstance","Jimp","jimpConfig","hasAlpha","encoders","decoders","constants","addToConfig","newConfig","Object","entries","forEach","key","value","addImageType","typeModule","type","Array","isArray","mime","addType","mimeType","addPlugin","pluginModule","plugin","jimpEvChange","types","plugins"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;AAOe,SAASA,SAAT,CAAmBC,aAAnB,EAAuD;AAAA,MAArBC,YAAqB,uEAANC,gBAAM;AACpE,MAAMC,UAAU,GAAG;AACjBC,IAAAA,QAAQ,EAAE,EADO;AAEjBC,IAAAA,QAAQ,EAAE,EAFO;AAGjBC,IAAAA,QAAQ,EAAE,EAHO;AAIjB,aAAO,EAJU;AAKjBC,IAAAA,SAAS,EAAE;AALM,GAAnB;;AAQA,WAASC,WAAT,CAAqBC,SAArB,EAAgC;AAC9BC,IAAAA,MAAM,CAACC,OAAP,CAAeF,SAAf,EAA0BG,OAA1B,CAAkC,gBAAkB;AAAA;AAAA,UAAhBC,GAAgB;AAAA,UAAXC,KAAW;;AAClDX,MAAAA,UAAU,CAACU,GAAD,CAAV,qBACKV,UAAU,CAACU,GAAD,CADf,MAEKC,KAFL;AAID,KALD;AAMD;;AAED,WAASC,YAAT,CAAsBC,UAAtB,EAAkC;AAChC,QAAMC,IAAI,GAAGD,UAAU,EAAvB;;AAEA,QAAIE,KAAK,CAACC,OAAN,CAAcF,IAAI,CAACG,IAAnB,CAAJ,EAA8B;AAC5BC,sEAAWJ,IAAI,CAACG,IAAhB;AACD,KAFD,MAEO;AACLV,MAAAA,MAAM,CAACC,OAAP,CAAeM,IAAI,CAACG,IAApB,EAA0BR,OAA1B,CAAkC,UAAAU,QAAQ;AAAA,eAAID,gEAAWC,QAAX,EAAJ;AAAA,OAA1C;AACD;;AAED,WAAOL,IAAI,CAACG,IAAZ;AACAZ,IAAAA,WAAW,CAACS,IAAD,CAAX;AACD;;AAED,WAASM,SAAT,CAAmBC,YAAnB,EAAiC;AAC/B,QAAMC,MAAM,GAAGD,YAAY,CAACE,kBAAD,CAAZ,IAA8B,EAA7C;;AACA,QAAI,CAACD,MAAM,SAAP,IAAiB,CAACA,MAAM,CAAClB,SAA7B,EAAwC;AACtC;AACAC,MAAAA,WAAW,CAAC;AAAE,iBAAOiB;AAAT,OAAD,CAAX;AACD,KAHD,MAGO;AACLjB,MAAAA,WAAW,CAACiB,MAAD,CAAX;AACD;AACF;;AAED,MAAIzB,aAAa,CAAC2B,KAAlB,EAAyB;AACvB3B,IAAAA,aAAa,CAAC2B,KAAd,CAAoBf,OAApB,CAA4BG,YAA5B;AAEAd,IAAAA,YAAY,CAACK,QAAb,qBACKL,YAAY,CAACK,QADlB,MAEKH,UAAU,CAACG,QAFhB;AAIAL,IAAAA,YAAY,CAACI,QAAb,qBACKJ,YAAY,CAACI,QADlB,MAEKF,UAAU,CAACE,QAFhB;AAIAJ,IAAAA,YAAY,CAACG,QAAb,qBACKH,YAAY,CAACG,QADlB,MAEKD,UAAU,CAACC,QAFhB;AAID;;AAED,MAAIJ,aAAa,CAAC4B,OAAlB,EAA2B;AACzB5B,IAAAA,aAAa,CAAC4B,OAAd,CAAsBhB,OAAtB,CAA8BW,SAA9B;AACD;;AAED,4BAAepB,UAAU,SAAzB,EAAiCF,YAAjC;AACA,0BAAaE,UAAU,CAACI,SAAxB,EAAmCN,YAAnC;AAEA,SAAOC,gBAAP;AACD","sourcesContent":["import Jimp, {\n addType,\n addJimpMethods,\n addConstants,\n jimpEvChange\n} from '@jimp/core';\n\nexport default function configure(configuration, jimpInstance = Jimp) {\n const jimpConfig = {\n hasAlpha: {},\n encoders: {},\n decoders: {},\n class: {},\n constants: {}\n };\n\n function addToConfig(newConfig) {\n Object.entries(newConfig).forEach(([key, value]) => {\n jimpConfig[key] = {\n ...jimpConfig[key],\n ...value\n };\n });\n }\n\n function addImageType(typeModule) {\n const type = typeModule();\n\n if (Array.isArray(type.mime)) {\n addType(...type.mime);\n } else {\n Object.entries(type.mime).forEach(mimeType => addType(...mimeType));\n }\n\n delete type.mime;\n addToConfig(type);\n }\n\n function addPlugin(pluginModule) {\n const plugin = pluginModule(jimpEvChange) || {};\n if (!plugin.class && !plugin.constants) {\n // Default to class function\n addToConfig({ class: plugin });\n } else {\n addToConfig(plugin);\n }\n }\n\n if (configuration.types) {\n configuration.types.forEach(addImageType);\n\n jimpInstance.decoders = {\n ...jimpInstance.decoders,\n ...jimpConfig.decoders\n };\n jimpInstance.encoders = {\n ...jimpInstance.encoders,\n ...jimpConfig.encoders\n };\n jimpInstance.hasAlpha = {\n ...jimpInstance.hasAlpha,\n ...jimpConfig.hasAlpha\n };\n }\n\n if (configuration.plugins) {\n configuration.plugins.forEach(addPlugin);\n }\n\n addJimpMethods(jimpConfig.class, jimpInstance);\n addConstants(jimpConfig.constants, jimpInstance);\n\n return Jimp;\n}\n"],"file":"index.js"}

View File

@@ -0,0 +1,28 @@
{
"name": "@jimp/custom",
"version": "0.10.3",
"description": "Interface to customize jimp configuration",
"main": "dist/index.js",
"module": "es/index.js",
"types": "types/index.d.ts",
"scripts": {
"build": "npm run build:node:production && npm run build:module",
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
"build:debug": "npm run build:node:debug",
"build:module": "cross-env BABEL_ENV=module babel src -d es --source-maps --config-file ../../babel.config.js",
"build:node": "babel src -d dist --source-maps --config-file ../../babel.config.js",
"build:node:debug": "cross-env BABEL_ENV=development npm run build:node",
"build:node:production": "cross-env BABEL_ENV=production npm run build:node"
},
"author": "",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.7.2",
"@jimp/core": "^0.10.3",
"core-js": "^3.4.1"
},
"publishConfig": {
"access": "public"
},
"gitHead": "37197106eae5c26231018dfdc0254422f6b43927"
}

View File

@@ -0,0 +1,74 @@
import Jimp, {
addType,
addJimpMethods,
addConstants,
jimpEvChange
} from '@jimp/core';
export default function configure(configuration, jimpInstance = Jimp) {
const jimpConfig = {
hasAlpha: {},
encoders: {},
decoders: {},
class: {},
constants: {}
};
function addToConfig(newConfig) {
Object.entries(newConfig).forEach(([key, value]) => {
jimpConfig[key] = {
...jimpConfig[key],
...value
};
});
}
function addImageType(typeModule) {
const type = typeModule();
if (Array.isArray(type.mime)) {
addType(...type.mime);
} else {
Object.entries(type.mime).forEach(mimeType => addType(...mimeType));
}
delete type.mime;
addToConfig(type);
}
function addPlugin(pluginModule) {
const plugin = pluginModule(jimpEvChange) || {};
if (!plugin.class && !plugin.constants) {
// Default to class function
addToConfig({ class: plugin });
} else {
addToConfig(plugin);
}
}
if (configuration.types) {
configuration.types.forEach(addImageType);
jimpInstance.decoders = {
...jimpInstance.decoders,
...jimpConfig.decoders
};
jimpInstance.encoders = {
...jimpInstance.encoders,
...jimpConfig.encoders
};
jimpInstance.hasAlpha = {
...jimpInstance.hasAlpha,
...jimpConfig.hasAlpha
};
}
if (configuration.plugins) {
configuration.plugins.forEach(addPlugin);
}
addJimpMethods(jimpConfig.class, jimpInstance);
addConstants(jimpConfig.constants, jimpInstance);
return Jimp;
}

View File

@@ -0,0 +1,34 @@
// TypeScript Version: 3.1
// See the `jimp` package index.d.ts for why the version is not 2.8
import {
FunctionRet,
Jimp,
JimpPlugin,
JimpType,
GetIntersectionFromPlugins,
GetIntersectionFromPluginsStatics,
JimpConstructors
} from '@jimp/core';
type JimpInstance<
TypesFuncArr extends FunctionRet<JimpType> | undefined,
PluginFuncArr extends FunctionRet<JimpPlugin> | undefined,
J extends JimpConstructors
> = J & GetIntersectionFromPluginsStatics<Exclude<TypesFuncArr | PluginFuncArr, undefined>> & {
prototype: JimpType & GetIntersectionFromPlugins<Exclude<TypesFuncArr | PluginFuncArr, undefined>>
};
declare function configure<
TypesFuncArr extends FunctionRet<JimpType> | undefined = undefined,
PluginFuncArr extends FunctionRet<JimpPlugin> | undefined = undefined,
J extends JimpConstructors = JimpConstructors
>(
configuration: {
types?: TypesFuncArr;
plugins?: PluginFuncArr;
},
jimpInstance?: J
// Since JimpInstance is required, we want to use the default `Jimp` type
): JimpInstance<TypesFuncArr, PluginFuncArr, J>;
export default configure;

View File

@@ -0,0 +1,404 @@
import configure from '@jimp/custom';
import gif from '@jimp/gif';
import png from '@jimp/png';
import displace from '@jimp/plugin-displace';
import resize from '@jimp/plugin-resize';
import scale from '@jimp/plugin-scale';
import types from '@jimp/types';
import plugins from '@jimp/plugins';
import * as Jimp from 'jimp';
// configure should return a valid Jimp type with addons
const CustomJimp = configure({
types: [gif, png],
plugins: [displace, resize]
});
test('should function the same as the `jimp` types', () => {
const FullCustomJimp = configure({
types: [types],
plugins: [plugins]
});
const jimpInst = new FullCustomJimp('test');
// Main Jimp export should already have all of these already applied
// $ExpectError
jimpInst.read('Test');
jimpInst.displace(jimpInst, 2);
jimpInst.resize(40, 40);
jimpInst.displace(jimpInst, 2);
jimpInst.shadow((err, val, coords) => {});
jimpInst.fishEye({r: 12});
jimpInst.circle({radius: 12, x: 12, y: 12});
// $ExpectError
jimpInst.PNG_FILTER_NONE;
// $ExpectError
jimpInst.test;
// $ExpectError
jimpInst.func();
// Main Jimp export should already have all of these already applied
FullCustomJimp.read('Test');
// $ExpectType 0
FullCustomJimp.PNG_FILTER_NONE;
// $ExpectError
FullCustomJimp.test;
// $ExpectError
FullCustomJimp.func();
test('can clone properly', async () => {
const baseImage = await FullCustomJimp.read('filename');
const cloneBaseImage = baseImage.clone();
// $ExpectType number
cloneBaseImage._deflateLevel;
test('can handle `this` returns on the core type properly', () => {
// $ExpectType number
cloneBaseImage.posterize(3)._quality
});
test('can handle `this` returns properly', () => {
cloneBaseImage
.resize(1, 1)
.crop(0, 0, 0, 0)
.mask(cloneBaseImage, 2, 2)
.print('a' as any, 2, 2, 'a' as any)
.resize(1, 1)
.quality(1)
.deflateLevel(2)
._filterType;
});
test('can handle imageCallbacks `this` properly', () => {
cloneBaseImage.rgba(false, (_, jimpCBIn) => {
// $ExpectError
jimpCBIn.read('Test');
jimpCBIn.displace(jimpInst, 2);
jimpCBIn.resize(40, 40);
// $ExpectType number
jimpCBIn._filterType;
// $ExpectError
jimpCBIn.test;
// $ExpectError
jimpCBIn.func();
})
})
});
test('Can handle callback with constructor', () => {
const myBmpBuffer: Buffer = {} as any;
Jimp.read(myBmpBuffer, (err, cbJimpInst) => {
// $ExpectError
cbJimpInst.read('Test');
cbJimpInst.displace(jimpInst, 2);
cbJimpInst.resize(40, 40);
// $ExpectType number
cbJimpInst._filterType;
// $ExpectError
cbJimpInst.test;
// $ExpectError
cbJimpInst.func();
});
});
});
test('can handle custom jimp', () => {
// Constants from types should be applied
// $ExpectType 0
CustomJimp.PNG_FILTER_NONE;
// Core functions should still work from Jimp
CustomJimp.read('Test');
// Constants should not(?) be applied from ill-formed plugins
// $ExpectError
CustomJimp.displace(CustomJimp, 2);
// Methods should be applied from well-formed plugins only to the instance
// $ExpectError
CustomJimp.resize(40, 40)
// Constants should be applied from well-formed plugins
CustomJimp.RESIZE_NEAREST_NEIGHBOR
// $ExpectError
CustomJimp.test;
// $ExpectError
CustomJimp.func();
const Jiimp = new CustomJimp('test');
// Methods from types should be applied
Jiimp.deflateLevel(4);
// Constants from types should be applied to the static only
// $ExpectError
Jiimp.PNG_FILTER_NONE;
// Core functions should still work from Jimp
Jiimp.getPixelColor(1, 1);
// Constants should be applied from ill-formed plugins
Jiimp.displace(Jiimp, 2);
// Methods should be applied from well-formed plugins
Jiimp.resize(40, 40)
// Constants should not be applied to the object
// $ExpectError
Jiimp.RESIZE_NEAREST_NEIGHBOR
// $ExpectError
Jiimp.test;
// $ExpectError
Jiimp.func();
});
test('can compose', () => {
const OtherCustomJimp = configure({
plugins: [scale]
}, CustomJimp);
// Constants from types should be applied
// $ExpectType 0
OtherCustomJimp.PNG_FILTER_NONE;
// Core functions should still work from Jimp
OtherCustomJimp.read('Test');
// Constants should not be applied to the static instance from ill-formed plugins
// $ExpectError
OtherCustomJimp.displace(OtherCustomJimp, 2);
// Methods should not be applied to the static instance from well-formed plugins
// $ExpectError
OtherCustomJimp.resize(40, 40);
// Constants should be applied from well-formed plugins
OtherCustomJimp.RESIZE_NEAREST_NEIGHBOR;
// $ExpectError
OtherCustomJimp.test;
// $ExpectError
OtherCustomJimp.func();
const Jiimp = new OtherCustomJimp('test');
// Methods from types should be applied
Jiimp.deflateLevel(4);
// Constants from types should not be applied to objects
// $ExpectError
Jiimp.PNG_FILTER_NONE;
// Methods from new plugins should be applied
Jiimp.scale(3);
// Methods from types should be applied
Jiimp.filterType(4);
// Core functions should still work from Jimp
Jiimp.getPixelColor(1, 1);
// Constants should be applied from ill-formed plugins
Jiimp.displace(Jiimp, 2);
// Methods should be applied from well-formed plugins
Jiimp.resize(40, 40)
// Constants should not be applied from well-formed plugins to objects
// $ExpectError
Jiimp.RESIZE_NEAREST_NEIGHBOR
// $ExpectError
Jiimp.test;
// $ExpectError
Jiimp.func();
});
test('can handle only plugins', () => {
const PluginsJimp = configure({
plugins: [plugins]
});
// Core functions should still work from Jimp
PluginsJimp.read('Test');
// Constants should not be applied from ill-formed plugins
// $ExpectError
PluginsJimp.displace(PluginsJimp, 2);
// Methods should be not be applied to from well-formed plugins to the top level
// $ExpectError
PluginsJimp.resize(40, 40);
// Constants should be applied from well-formed plugins
// $ExpectType "nearestNeighbor"
PluginsJimp.RESIZE_NEAREST_NEIGHBOR;
// $ExpectError
PluginsJimp.test;
// $ExpectError
PluginsJimp.func();
const Jiimp = new PluginsJimp('test');
// Core functions should still work from Jimp
Jiimp.getPixelColor(1, 1);
// Constants should be applied from ill-formed plugins
Jiimp.displace(Jiimp, 2);
// Methods should be applied from well-formed plugins
Jiimp.resize(40, 40)
// Constants should be not applied to objects from well-formed plugins
// $ExpectError
Jiimp.RESIZE_NEAREST_NEIGHBOR
// $ExpectError
Jiimp.test;
// $ExpectError
Jiimp.func();
})
test('can handle only all types', () => {
const TypesJimp = configure({
types: [types]
});
// Methods from types should not be applied
// $ExpectError
TypesJimp.filterType(4);
// Constants from types should be applied
// $ExpectType 0
TypesJimp.PNG_FILTER_NONE;
// $ExpectError
TypesJimp.test;
// $ExpectError
TypesJimp.func();
const Jiimp = new TypesJimp('test');
// Methods from types should be applied
Jiimp.filterType(4);
// Constants from types should be not applied to objects
// $ExpectError
Jiimp.PNG_FILTER_NONE;
// $ExpectError
Jiimp.test;
// $ExpectError
Jiimp.func();
});
test('can handle only one type', () => {
const PngJimp = configure({
types: [png]
});
// Constants from other types should be not applied
// $ExpectError
PngJimp.MIME_TIFF;
// Constants from types should be applied
// $ExpectType 0
PngJimp.PNG_FILTER_NONE;
// $ExpectError
PngJimp.test;
// $ExpectError
PngJimp.func();
const Jiimp = new PngJimp('test');
// Constants from other types should be not applied
// $ExpectError
Jiimp.MIME_TIFF;
// Constants from types should not be applied to objects
// $ExpectError
Jiimp.PNG_FILTER_NONE;
// $ExpectError
Jiimp.test;
// $ExpectError
Jiimp.func();
});
test('can handle only one plugin', () => {
const ResizeJimp = configure({
plugins: [resize]
});
// Constants from other plugins should be not applied
// $ExpectError
ResizeJimp.FONT_SANS_8_BLACK;
// Constants from plugin should be applied
// $ExpectType "nearestNeighbor"
ResizeJimp.RESIZE_NEAREST_NEIGHBOR;
// $ExpectError
ResizeJimp.resize(2, 2);
// $ExpectError
ResizeJimp.test;
// $ExpectError
ResizeJimp.func();
const Jiimp: InstanceType<typeof ResizeJimp> = new ResizeJimp('test');
// Constants from other plugins should be not applied
// $ExpectError
Jiimp.FONT_SANS_8_BLACK;
// Constants from plugin should not be applied to the object
// $ExpectError
Jiimp.RESIZE_NEAREST_NEIGHBOR;
Jiimp.resize(2, 2);
// $ExpectError
Jiimp.test;
// $ExpectError
Jiimp.func();
});
test('Can handle appendConstructorOption', () => {
const AppendJimp = configure({});
AppendJimp.appendConstructorOption(
'Name of Option',
args => args.hasSomeCustomThing,
function(resolve, reject, args) {
// $ExpectError
this.bitmap = 3;
// $ExpectError
AppendJimp.resize(2, 2);
resolve();
}
);
});

View File

@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noEmit": true,
// If the library is an external module (uses `export`), this allows your test file to import "mylib" instead of "./index".
// If the library is global (cannot be imported via `import` or `require`), leave this out.
"baseUrl": ".",
"paths": {
"mylib": ["."]
}
}
}

View File

@@ -0,0 +1,11 @@
# v0.9.3 (Tue Nov 26 2019)
#### 🐛 Bug Fix
- `@jimp/cli`, `@jimp/core`, `@jimp/custom`, `jimp`, `@jimp/plugin-blit`, `@jimp/plugin-blur`, `@jimp/plugin-circle`, `@jimp/plugin-color`, `@jimp/plugin-contain`, `@jimp/plugin-cover`, `@jimp/plugin-crop`, `@jimp/plugin-displace`, `@jimp/plugin-dither`, `@jimp/plugin-fisheye`, `@jimp/plugin-flip`, `@jimp/plugin-gaussian`, `@jimp/plugin-invert`, `@jimp/plugin-mask`, `@jimp/plugin-normalize`, `@jimp/plugin-print`, `@jimp/plugin-resize`, `@jimp/plugin-rotate`, `@jimp/plugin-scale`, `@jimp/plugin-shadow`, `@jimp/plugin-threshold`, `@jimp/plugins`, `@jimp/test-utils`, `@jimp/bmp`, `@jimp/gif`, `@jimp/jpeg`, `@jimp/png`, `@jimp/tiff`, `@jimp/types`, `@jimp/utils`
- Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 2
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))

21
uni_modules/UniDevTools/node_modules/@jimp/gif/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Oliver Moran
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.

View File

@@ -0,0 +1,8 @@
<div align="center">
<img width="200" height="200"
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
<h1>@jimp/gif</h1>
<p>Default Jimp gif decoder.</p>
</div>
NOTE: Encoder currently unavailable.

View File

@@ -0,0 +1,37 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _omggif = _interopRequireDefault(require("omggif"));
var MIME_TYPE = 'image/gif';
var _default = function _default() {
return {
mime: (0, _defineProperty2["default"])({}, MIME_TYPE, ['gif']),
constants: {
MIME_GIF: MIME_TYPE
},
decoders: (0, _defineProperty2["default"])({}, MIME_TYPE, function (data) {
var gifObj = new _omggif["default"].GifReader(data);
var gifData = Buffer.alloc(gifObj.width * gifObj.height * 4);
gifObj.decodeAndBlitFrameRGBA(0, gifData);
return {
data: gifData,
width: gifObj.width,
height: gifObj.height
};
})
};
};
exports["default"] = _default;
module.exports = exports.default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":["MIME_TYPE","mime","constants","MIME_GIF","decoders","data","gifObj","GIF","GifReader","gifData","Buffer","alloc","width","height","decodeAndBlitFrameRGBA"],"mappings":";;;;;;;;;;;AAAA;;AAEA,IAAMA,SAAS,GAAG,WAAlB;;eAEe;AAAA,SAAO;AACpBC,IAAAA,IAAI,uCAAKD,SAAL,EAAiB,CAAC,KAAD,CAAjB,CADgB;AAGpBE,IAAAA,SAAS,EAAE;AACTC,MAAAA,QAAQ,EAAEH;AADD,KAHS;AAOpBI,IAAAA,QAAQ,uCACLJ,SADK,EACO,UAAAK,IAAI,EAAI;AACnB,UAAMC,MAAM,GAAG,IAAIC,mBAAIC,SAAR,CAAkBH,IAAlB,CAAf;AACA,UAAMI,OAAO,GAAGC,MAAM,CAACC,KAAP,CAAaL,MAAM,CAACM,KAAP,GAAeN,MAAM,CAACO,MAAtB,GAA+B,CAA5C,CAAhB;AAEAP,MAAAA,MAAM,CAACQ,sBAAP,CAA8B,CAA9B,EAAiCL,OAAjC;AAEA,aAAO;AACLJ,QAAAA,IAAI,EAAEI,OADD;AAELG,QAAAA,KAAK,EAAEN,MAAM,CAACM,KAFT;AAGLC,QAAAA,MAAM,EAAEP,MAAM,CAACO;AAHV,OAAP;AAKD,KAZK;AAPY,GAAP;AAAA,C","sourcesContent":["import GIF from 'omggif';\n\nconst MIME_TYPE = 'image/gif';\n\nexport default () => ({\n mime: { [MIME_TYPE]: ['gif'] },\n\n constants: {\n MIME_GIF: MIME_TYPE\n },\n\n decoders: {\n [MIME_TYPE]: data => {\n const gifObj = new GIF.GifReader(data);\n const gifData = Buffer.alloc(gifObj.width * gifObj.height * 4);\n\n gifObj.decodeAndBlitFrameRGBA(0, gifData);\n\n return {\n data: gifData,\n width: gifObj.width,\n height: gifObj.height\n };\n }\n }\n});\n"],"file":"index.js"}

View File

@@ -0,0 +1,36 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _omggif = _interopRequireDefault(require("omggif"));
var MIME_TYPE = 'image/gif';
var _default = function _default() {
return {
mime: (0, _defineProperty2["default"])({}, MIME_TYPE, ['gif']),
constants: {
MIME_GIF: MIME_TYPE
},
decoders: (0, _defineProperty2["default"])({}, MIME_TYPE, function (data) {
var gifObj = new _omggif["default"].GifReader(data);
var gifData = Buffer.alloc(gifObj.width * gifObj.height * 4);
gifObj.decodeAndBlitFrameRGBA(0, gifData);
return {
data: gifData,
width: gifObj.width,
height: gifObj.height
};
})
};
};
exports["default"] = _default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":["MIME_TYPE","mime","constants","MIME_GIF","decoders","data","gifObj","GIF","GifReader","gifData","Buffer","alloc","width","height","decodeAndBlitFrameRGBA"],"mappings":";;;;;;;;;;;AAAA;;AAEA,IAAMA,SAAS,GAAG,WAAlB;;eAEe;AAAA,SAAO;AACpBC,IAAAA,IAAI,uCAAKD,SAAL,EAAiB,CAAC,KAAD,CAAjB,CADgB;AAGpBE,IAAAA,SAAS,EAAE;AACTC,MAAAA,QAAQ,EAAEH;AADD,KAHS;AAOpBI,IAAAA,QAAQ,uCACLJ,SADK,EACO,UAAAK,IAAI,EAAI;AACnB,UAAMC,MAAM,GAAG,IAAIC,mBAAIC,SAAR,CAAkBH,IAAlB,CAAf;AACA,UAAMI,OAAO,GAAGC,MAAM,CAACC,KAAP,CAAaL,MAAM,CAACM,KAAP,GAAeN,MAAM,CAACO,MAAtB,GAA+B,CAA5C,CAAhB;AAEAP,MAAAA,MAAM,CAACQ,sBAAP,CAA8B,CAA9B,EAAiCL,OAAjC;AAEA,aAAO;AACLJ,QAAAA,IAAI,EAAEI,OADD;AAELG,QAAAA,KAAK,EAAEN,MAAM,CAACM,KAFT;AAGLC,QAAAA,MAAM,EAAEP,MAAM,CAACO;AAHV,OAAP;AAKD,KAZK;AAPY,GAAP;AAAA,C","sourcesContent":["import GIF from 'omggif';\n\nconst MIME_TYPE = 'image/gif';\n\nexport default () => ({\n mime: { [MIME_TYPE]: ['gif'] },\n\n constants: {\n MIME_GIF: MIME_TYPE\n },\n\n decoders: {\n [MIME_TYPE]: data => {\n const gifObj = new GIF.GifReader(data);\n const gifData = Buffer.alloc(gifObj.width * gifObj.height * 4);\n\n gifObj.decodeAndBlitFrameRGBA(0, gifData);\n\n return {\n data: gifData,\n width: gifObj.width,\n height: gifObj.height\n };\n }\n }\n});\n"],"file":"index.js"}

View File

@@ -0,0 +1,17 @@
import { DecoderFn } from '@jimp/core';
interface Gif {
mime: {
'image/gif': string[]
}
constants: {
MIME_GIF: 'image/gif';
}
decoders: {
'image/gif': DecoderFn
}
}
export default function(): Gif;

View File

@@ -0,0 +1,32 @@
{
"name": "@jimp/gif",
"version": "0.10.3",
"description": "Default Jimp gif encoder/decoder.",
"main": "dist/index.js",
"module": "es/index.js",
"types": "index.d.ts",
"scripts": {
"build": "npm run build:node:production && npm run build:module",
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
"build:debug": "npm run build:node:debug",
"build:module": "cross-env BABEL_ENV=module babel src -d es --source-maps --config-file ../../babel.config.js",
"build:node": "babel src -d dist --source-maps --config-file ../../babel.config.js",
"build:node:debug": "cross-env BABEL_ENV=development npm run build:node",
"build:node:production": "cross-env BABEL_ENV=production npm run build:node"
},
"author": "",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.7.2",
"@jimp/utils": "^0.10.3",
"core-js": "^3.4.1",
"omggif": "^1.0.9"
},
"peerDependencies": {
"@jimp/custom": ">=0.3.5"
},
"publishConfig": {
"access": "public"
},
"gitHead": "37197106eae5c26231018dfdc0254422f6b43927"
}

View File

@@ -0,0 +1,26 @@
import GIF from 'omggif';
const MIME_TYPE = 'image/gif';
export default () => ({
mime: { [MIME_TYPE]: ['gif'] },
constants: {
MIME_GIF: MIME_TYPE
},
decoders: {
[MIME_TYPE]: data => {
const gifObj = new GIF.GifReader(data);
const gifData = Buffer.alloc(gifObj.width * gifObj.height * 4);
gifObj.decodeAndBlitFrameRGBA(0, gifData);
return {
data: gifData,
width: gifObj.width,
height: gifObj.height
};
}
}
});

View File

@@ -0,0 +1,23 @@
# v0.10.0 (Mon Mar 30 2020)
#### 🚀 Enhancement
- Properly split constructor and instance types [#867](https://github.com/oliver-moran/jimp/pull/867) ([@forivall](https://github.com/forivall))
#### Authors: 1
- Emily Marigold Klassen ([@forivall](https://github.com/forivall))
---
# v0.9.3 (Tue Nov 26 2019)
#### 🐛 Bug Fix
- `@jimp/cli`, `@jimp/core`, `@jimp/custom`, `jimp`, `@jimp/plugin-blit`, `@jimp/plugin-blur`, `@jimp/plugin-circle`, `@jimp/plugin-color`, `@jimp/plugin-contain`, `@jimp/plugin-cover`, `@jimp/plugin-crop`, `@jimp/plugin-displace`, `@jimp/plugin-dither`, `@jimp/plugin-fisheye`, `@jimp/plugin-flip`, `@jimp/plugin-gaussian`, `@jimp/plugin-invert`, `@jimp/plugin-mask`, `@jimp/plugin-normalize`, `@jimp/plugin-print`, `@jimp/plugin-resize`, `@jimp/plugin-rotate`, `@jimp/plugin-scale`, `@jimp/plugin-shadow`, `@jimp/plugin-threshold`, `@jimp/plugins`, `@jimp/test-utils`, `@jimp/bmp`, `@jimp/gif`, `@jimp/jpeg`, `@jimp/png`, `@jimp/tiff`, `@jimp/types`, `@jimp/utils`
- Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 2
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Oliver Moran
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.

View File

@@ -0,0 +1,12 @@
<div align="center">
<img width="200" height="200"
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
<h1>@jimp/jpeg</h1>
<p>Default Jimp jpeg encoder/decoder.</p>
</div>
## Available Methods
### Jimp.quality
Sets the quality of the image when saving as JPEG format (default is 100)

View File

@@ -0,0 +1,61 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _jpegJs = _interopRequireDefault(require("jpeg-js"));
var _utils = require("@jimp/utils");
var MIME_TYPE = 'image/jpeg';
var _default = function _default() {
return {
mime: (0, _defineProperty2["default"])({}, MIME_TYPE, ['jpeg', 'jpg', 'jpe']),
constants: {
MIME_JPEG: MIME_TYPE
},
decoders: (0, _defineProperty2["default"])({}, MIME_TYPE, _jpegJs["default"].decode),
encoders: (0, _defineProperty2["default"])({}, MIME_TYPE, function (image) {
return _jpegJs["default"].encode(image.bitmap, image._quality).data;
}),
"class": {
// The quality to be used when saving JPEG images
_quality: 100,
/**
* Sets the quality of the image when saving as JPEG format (default is 100)
* @param {number} n The quality to use 0-100
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
quality: function quality(n, cb) {
if (typeof n !== 'number') {
return _utils.throwError.call(this, 'n must be a number', cb);
}
if (n < 0 || n > 100) {
return _utils.throwError.call(this, 'n must be a number 0 - 100', cb);
}
this._quality = Math.round(n);
if ((0, _utils.isNodePattern)(cb)) {
cb.call(this, null, this);
}
return this;
}
}
};
};
exports["default"] = _default;
module.exports = exports.default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":["MIME_TYPE","mime","constants","MIME_JPEG","decoders","JPEG","decode","encoders","image","encode","bitmap","_quality","data","quality","n","cb","throwError","call","Math","round"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA,IAAMA,SAAS,GAAG,YAAlB;;eAEe;AAAA,SAAO;AACpBC,IAAAA,IAAI,uCAAKD,SAAL,EAAiB,CAAC,MAAD,EAAS,KAAT,EAAgB,KAAhB,CAAjB,CADgB;AAGpBE,IAAAA,SAAS,EAAE;AACTC,MAAAA,SAAS,EAAEH;AADF,KAHS;AAOpBI,IAAAA,QAAQ,uCACLJ,SADK,EACOK,mBAAKC,MADZ,CAPY;AAWpBC,IAAAA,QAAQ,uCACLP,SADK,EACO,UAAAQ,KAAK;AAAA,aAAIH,mBAAKI,MAAL,CAAYD,KAAK,CAACE,MAAlB,EAA0BF,KAAK,CAACG,QAAhC,EAA0CC,IAA9C;AAAA,KADZ,CAXY;AAepB,aAAO;AACL;AACAD,MAAAA,QAAQ,EAAE,GAFL;;AAGL;;;;;;AAMAE,MAAAA,OATK,mBASGC,CATH,EASMC,EATN,EASU;AACb,YAAI,OAAOD,CAAP,KAAa,QAAjB,EAA2B;AACzB,iBAAOE,kBAAWC,IAAX,CAAgB,IAAhB,EAAsB,oBAAtB,EAA4CF,EAA5C,CAAP;AACD;;AAED,YAAID,CAAC,GAAG,CAAJ,IAASA,CAAC,GAAG,GAAjB,EAAsB;AACpB,iBAAOE,kBAAWC,IAAX,CAAgB,IAAhB,EAAsB,4BAAtB,EAAoDF,EAApD,CAAP;AACD;;AAED,aAAKJ,QAAL,GAAgBO,IAAI,CAACC,KAAL,CAAWL,CAAX,CAAhB;;AAEA,YAAI,0BAAcC,EAAd,CAAJ,EAAuB;AACrBA,UAAAA,EAAE,CAACE,IAAH,CAAQ,IAAR,EAAc,IAAd,EAAoB,IAApB;AACD;;AAED,eAAO,IAAP;AACD;AAzBI;AAfa,GAAP;AAAA,C","sourcesContent":["import JPEG from 'jpeg-js';\nimport { throwError, isNodePattern } from '@jimp/utils';\n\nconst MIME_TYPE = 'image/jpeg';\n\nexport default () => ({\n mime: { [MIME_TYPE]: ['jpeg', 'jpg', 'jpe'] },\n\n constants: {\n MIME_JPEG: MIME_TYPE\n },\n\n decoders: {\n [MIME_TYPE]: JPEG.decode\n },\n\n encoders: {\n [MIME_TYPE]: image => JPEG.encode(image.bitmap, image._quality).data\n },\n\n class: {\n // The quality to be used when saving JPEG images\n _quality: 100,\n /**\n * Sets the quality of the image when saving as JPEG format (default is 100)\n * @param {number} n The quality to use 0-100\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\n quality(n, cb) {\n if (typeof n !== 'number') {\n return throwError.call(this, 'n must be a number', cb);\n }\n\n if (n < 0 || n > 100) {\n return throwError.call(this, 'n must be a number 0 - 100', cb);\n }\n\n this._quality = Math.round(n);\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n }\n }\n});\n"],"file":"index.js"}

View File

@@ -0,0 +1,60 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _jpegJs = _interopRequireDefault(require("jpeg-js"));
var _utils = require("@jimp/utils");
var MIME_TYPE = 'image/jpeg';
var _default = function _default() {
return {
mime: (0, _defineProperty2["default"])({}, MIME_TYPE, ['jpeg', 'jpg', 'jpe']),
constants: {
MIME_JPEG: MIME_TYPE
},
decoders: (0, _defineProperty2["default"])({}, MIME_TYPE, _jpegJs["default"].decode),
encoders: (0, _defineProperty2["default"])({}, MIME_TYPE, function (image) {
return _jpegJs["default"].encode(image.bitmap, image._quality).data;
}),
"class": {
// The quality to be used when saving JPEG images
_quality: 100,
/**
* Sets the quality of the image when saving as JPEG format (default is 100)
* @param {number} n The quality to use 0-100
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
quality: function quality(n, cb) {
if (typeof n !== 'number') {
return _utils.throwError.call(this, 'n must be a number', cb);
}
if (n < 0 || n > 100) {
return _utils.throwError.call(this, 'n must be a number 0 - 100', cb);
}
this._quality = Math.round(n);
if ((0, _utils.isNodePattern)(cb)) {
cb.call(this, null, this);
}
return this;
}
}
};
};
exports["default"] = _default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":["MIME_TYPE","mime","constants","MIME_JPEG","decoders","JPEG","decode","encoders","image","encode","bitmap","_quality","data","quality","n","cb","throwError","call","Math","round"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA,IAAMA,SAAS,GAAG,YAAlB;;eAEe;AAAA,SAAO;AACpBC,IAAAA,IAAI,uCAAKD,SAAL,EAAiB,CAAC,MAAD,EAAS,KAAT,EAAgB,KAAhB,CAAjB,CADgB;AAGpBE,IAAAA,SAAS,EAAE;AACTC,MAAAA,SAAS,EAAEH;AADF,KAHS;AAOpBI,IAAAA,QAAQ,uCACLJ,SADK,EACOK,mBAAKC,MADZ,CAPY;AAWpBC,IAAAA,QAAQ,uCACLP,SADK,EACO,UAAAQ,KAAK;AAAA,aAAIH,mBAAKI,MAAL,CAAYD,KAAK,CAACE,MAAlB,EAA0BF,KAAK,CAACG,QAAhC,EAA0CC,IAA9C;AAAA,KADZ,CAXY;AAepB,aAAO;AACL;AACAD,MAAAA,QAAQ,EAAE,GAFL;;AAGL;;;;;;AAMAE,MAAAA,OATK,mBASGC,CATH,EASMC,EATN,EASU;AACb,YAAI,OAAOD,CAAP,KAAa,QAAjB,EAA2B;AACzB,iBAAOE,kBAAWC,IAAX,CAAgB,IAAhB,EAAsB,oBAAtB,EAA4CF,EAA5C,CAAP;AACD;;AAED,YAAID,CAAC,GAAG,CAAJ,IAASA,CAAC,GAAG,GAAjB,EAAsB;AACpB,iBAAOE,kBAAWC,IAAX,CAAgB,IAAhB,EAAsB,4BAAtB,EAAoDF,EAApD,CAAP;AACD;;AAED,aAAKJ,QAAL,GAAgBO,IAAI,CAACC,KAAL,CAAWL,CAAX,CAAhB;;AAEA,YAAI,0BAAcC,EAAd,CAAJ,EAAuB;AACrBA,UAAAA,EAAE,CAACE,IAAH,CAAQ,IAAR,EAAc,IAAd,EAAoB,IAApB;AACD;;AAED,eAAO,IAAP;AACD;AAzBI;AAfa,GAAP;AAAA,C","sourcesContent":["import JPEG from 'jpeg-js';\nimport { throwError, isNodePattern } from '@jimp/utils';\n\nconst MIME_TYPE = 'image/jpeg';\n\nexport default () => ({\n mime: { [MIME_TYPE]: ['jpeg', 'jpg', 'jpe'] },\n\n constants: {\n MIME_JPEG: MIME_TYPE\n },\n\n decoders: {\n [MIME_TYPE]: JPEG.decode\n },\n\n encoders: {\n [MIME_TYPE]: image => JPEG.encode(image.bitmap, image._quality).data\n },\n\n class: {\n // The quality to be used when saving JPEG images\n _quality: 100,\n /**\n * Sets the quality of the image when saving as JPEG format (default is 100)\n * @param {number} n The quality to use 0-100\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\n quality(n, cb) {\n if (typeof n !== 'number') {\n return throwError.call(this, 'n must be a number', cb);\n }\n\n if (n < 0 || n > 100) {\n return throwError.call(this, 'n must be a number 0 - 100', cb);\n }\n\n this._quality = Math.round(n);\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n }\n }\n});\n"],"file":"index.js"}

View File

@@ -0,0 +1,26 @@
import { DecoderFn, EncoderFn, ImageCallback } from '@jimp/core';
interface JpegClass {
_quality: number;
quality: (n: number, cb?: ImageCallback<this>) => this;
}
interface Jpeg {
mime: { 'image/jpeg': string[] },
constants: {
MIME_JPEG: 'image/jpeg';
}
encoders: {
'image/jpeg': EncoderFn
}
decoders: {
'image/jpeg': DecoderFn
}
class: JpegClass
}
export default function(): Jpeg;

View File

@@ -0,0 +1,39 @@
{
"name": "@jimp/jpeg",
"version": "0.10.3",
"description": "Default Jimp jpeg encoder/decoder.",
"main": "dist/index.js",
"module": "es/index.js",
"types": "index.d.ts",
"scripts": {
"test": "cross-env BABEL_ENV=test mocha --require @babel/register",
"test:watch": "npm run test -- --reporter min --watch",
"test:coverage": "nyc npm run test",
"build": "npm run build:node:production && npm run build:module",
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
"build:debug": "npm run build:node:debug",
"build:module": "cross-env BABEL_ENV=module babel src -d es --source-maps --config-file ../../babel.config.js",
"build:node": "babel src -d dist --source-maps --config-file ../../babel.config.js",
"build:node:debug": "cross-env BABEL_ENV=development npm run build:node",
"build:node:production": "cross-env BABEL_ENV=production npm run build:node"
},
"author": "",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.7.2",
"@jimp/utils": "^0.10.3",
"core-js": "^3.4.1",
"jpeg-js": "^0.3.4"
},
"peerDependencies": {
"@jimp/custom": ">=0.3.5"
},
"devDependencies": {
"@jimp/custom": "^0.10.3",
"@jimp/test-utils": "^0.10.3"
},
"publishConfig": {
"access": "public"
},
"gitHead": "37197106eae5c26231018dfdc0254422f6b43927"
}

View File

@@ -0,0 +1,48 @@
import JPEG from 'jpeg-js';
import { throwError, isNodePattern } from '@jimp/utils';
const MIME_TYPE = 'image/jpeg';
export default () => ({
mime: { [MIME_TYPE]: ['jpeg', 'jpg', 'jpe'] },
constants: {
MIME_JPEG: MIME_TYPE
},
decoders: {
[MIME_TYPE]: JPEG.decode
},
encoders: {
[MIME_TYPE]: image => JPEG.encode(image.bitmap, image._quality).data
},
class: {
// The quality to be used when saving JPEG images
_quality: 100,
/**
* Sets the quality of the image when saving as JPEG format (default is 100)
* @param {number} n The quality to use 0-100
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
quality(n, cb) {
if (typeof n !== 'number') {
return throwError.call(this, 'n must be a number', cb);
}
if (n < 0 || n > 100) {
return throwError.call(this, 'n must be a number 0 - 100', cb);
}
this._quality = Math.round(n);
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
}
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

View File

@@ -0,0 +1,48 @@
import { Jimp, getTestDir } from '@jimp/test-utils';
import configure from '@jimp/custom';
import jpeg from '../src';
const jimp = configure({ types: [jpeg] }, Jimp);
describe('JPEG', () => {
const imagesDir = getTestDir(__dirname) + '/images';
it('load JPG', async () => {
const image = await jimp.read(imagesDir + '/cops.jpg');
image.getPixelColor(10, 10).should.be.equal(0x3f4a02ff);
image.getPixelColor(220, 190).should.be.equal(0x5d94b6ff);
image.getPixelColor(350, 130).should.be.equal(0xdf7944ff);
});
it('load JPG with fill bytes', async () => {
const image = await jimp.read(imagesDir + '/fillbytes.jpg');
image.getPixelColor(10, 10).should.be.equal(0xaeb8c3ff);
image.getPixelColor(220, 190).should.be.equal(0x262b21ff);
image.getPixelColor(350, 130).should.be.equal(0x4e5d30ff);
});
it('export JPG', async () => {
const image = await jimp.read({
width: 3,
height: 3,
data: [
0xff0000ff,
0xff0080ff,
0xff00ffff,
0xff0080ff,
0xff00ffff,
0x8000ffff,
0xff00ffff,
0x8000ffff,
0x0000ffff
]
});
image.quality(50);
const buffer = await image.getBufferAsync('image/jpeg');
buffer.toString().should.match(/^.{3,9}JFIF\u0000/);
});
});

View File

@@ -0,0 +1,11 @@
# v0.9.3 (Tue Nov 26 2019)
#### 🐛 Bug Fix
- `@jimp/cli`, `@jimp/core`, `@jimp/custom`, `jimp`, `@jimp/plugin-blit`, `@jimp/plugin-blur`, `@jimp/plugin-circle`, `@jimp/plugin-color`, `@jimp/plugin-contain`, `@jimp/plugin-cover`, `@jimp/plugin-crop`, `@jimp/plugin-displace`, `@jimp/plugin-dither`, `@jimp/plugin-fisheye`, `@jimp/plugin-flip`, `@jimp/plugin-gaussian`, `@jimp/plugin-invert`, `@jimp/plugin-mask`, `@jimp/plugin-normalize`, `@jimp/plugin-print`, `@jimp/plugin-resize`, `@jimp/plugin-rotate`, `@jimp/plugin-scale`, `@jimp/plugin-shadow`, `@jimp/plugin-threshold`, `@jimp/plugins`, `@jimp/test-utils`, `@jimp/bmp`, `@jimp/gif`, `@jimp/jpeg`, `@jimp/png`, `@jimp/tiff`, `@jimp/types`, `@jimp/utils`
- Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 2
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Oliver Moran
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.

View File

@@ -0,0 +1,34 @@
<div align="center">
<img width="200" height="200"
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
<h1>@jimp/plugin-blit</h1>
<p>Blit an image.</p>
</div>
> Blit - a data operation commonly used in computer graphics in which several bitmaps are combined into one using a boolean function.
## Usage
Blits a source image on to this image
- @param {Jimp} src image to blit
- @param {number} x the x position to blit the image
- @param {number} y the y position to blit the image
- @param {number} srcx (optional) the x position from which to crop the source image
- @param {number} srcy (optional) the y position from which to crop the source image
- @param {number} srcw (optional) the width to which to crop the source image
- @param {number} srch (optional) the height to which to crop the source image
- @param {function(Error, Jimp)} cb (optional) a callback for when complete
```js
import jimp from 'jimp';
async function main() {
const image = await jimp.read('test/image.png');
const parrot = await jimp.read('test/party-parrot.png');
image.blit(parrot, x, y);
}
main();
```

View File

@@ -0,0 +1,99 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _utils = require("@jimp/utils");
var _default = function _default() {
return {
/**
* Blits a source image on to this image
* @param {Jimp} src the source Jimp instance
* @param {number} x the x position to blit the image
* @param {number} y the y position to blit the image
* @param {number} srcx (optional) the x position from which to crop the source image
* @param {number} srcy (optional) the y position from which to crop the source image
* @param {number} srcw (optional) the width to which to crop the source image
* @param {number} srch (optional) the height to which to crop the source image
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
blit: function blit(src, x, y, srcx, srcy, srcw, srch, cb) {
if (!(src instanceof this.constructor)) {
return _utils.throwError.call(this, 'The source must be a Jimp image', cb);
}
if (typeof x !== 'number' || typeof y !== 'number') {
return _utils.throwError.call(this, 'x and y must be numbers', cb);
}
if (typeof srcx === 'function') {
cb = srcx;
srcx = 0;
srcy = 0;
srcw = src.bitmap.width;
srch = src.bitmap.height;
} else if ((0, _typeof2["default"])(srcx) === (0, _typeof2["default"])(srcy) && (0, _typeof2["default"])(srcy) === (0, _typeof2["default"])(srcw) && (0, _typeof2["default"])(srcw) === (0, _typeof2["default"])(srch)) {
srcx = srcx || 0;
srcy = srcy || 0;
srcw = srcw || src.bitmap.width;
srch = srch || src.bitmap.height;
} else {
return _utils.throwError.call(this, 'srcx, srcy, srcw, srch must be numbers', cb);
} // round input
x = Math.round(x);
y = Math.round(y); // round input
srcx = Math.round(srcx);
srcy = Math.round(srcy);
srcw = Math.round(srcw);
srch = Math.round(srch);
var maxWidth = this.bitmap.width;
var maxHeight = this.bitmap.height;
var baseImage = this;
src.scanQuiet(srcx, srcy, srcw, srch, function (sx, sy, idx) {
var xOffset = x + sx - srcx;
var yOffset = y + sy - srcy;
if (xOffset >= 0 && yOffset >= 0 && maxWidth - xOffset > 0 && maxHeight - yOffset > 0) {
var dstIdx = baseImage.getPixelIndex(xOffset, yOffset);
var _src = {
r: this.bitmap.data[idx],
g: this.bitmap.data[idx + 1],
b: this.bitmap.data[idx + 2],
a: this.bitmap.data[idx + 3]
};
var dst = {
r: baseImage.bitmap.data[dstIdx],
g: baseImage.bitmap.data[dstIdx + 1],
b: baseImage.bitmap.data[dstIdx + 2],
a: baseImage.bitmap.data[dstIdx + 3]
};
baseImage.bitmap.data[dstIdx] = (_src.a * (_src.r - dst.r) - dst.r + 255 >> 8) + dst.r;
baseImage.bitmap.data[dstIdx + 1] = (_src.a * (_src.g - dst.g) - dst.g + 255 >> 8) + dst.g;
baseImage.bitmap.data[dstIdx + 2] = (_src.a * (_src.b - dst.b) - dst.b + 255 >> 8) + dst.b;
baseImage.bitmap.data[dstIdx + 3] = this.constructor.limit255(dst.a + _src.a);
}
});
if ((0, _utils.isNodePattern)(cb)) {
cb.call(this, null, this);
}
return this;
}
};
};
exports["default"] = _default;
module.exports = exports.default;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,98 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _utils = require("@jimp/utils");
var _default = function _default() {
return {
/**
* Blits a source image on to this image
* @param {Jimp} src the source Jimp instance
* @param {number} x the x position to blit the image
* @param {number} y the y position to blit the image
* @param {number} srcx (optional) the x position from which to crop the source image
* @param {number} srcy (optional) the y position from which to crop the source image
* @param {number} srcw (optional) the width to which to crop the source image
* @param {number} srch (optional) the height to which to crop the source image
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
blit: function blit(src, x, y, srcx, srcy, srcw, srch, cb) {
if (!(src instanceof this.constructor)) {
return _utils.throwError.call(this, 'The source must be a Jimp image', cb);
}
if (typeof x !== 'number' || typeof y !== 'number') {
return _utils.throwError.call(this, 'x and y must be numbers', cb);
}
if (typeof srcx === 'function') {
cb = srcx;
srcx = 0;
srcy = 0;
srcw = src.bitmap.width;
srch = src.bitmap.height;
} else if ((0, _typeof2["default"])(srcx) === (0, _typeof2["default"])(srcy) && (0, _typeof2["default"])(srcy) === (0, _typeof2["default"])(srcw) && (0, _typeof2["default"])(srcw) === (0, _typeof2["default"])(srch)) {
srcx = srcx || 0;
srcy = srcy || 0;
srcw = srcw || src.bitmap.width;
srch = srch || src.bitmap.height;
} else {
return _utils.throwError.call(this, 'srcx, srcy, srcw, srch must be numbers', cb);
} // round input
x = Math.round(x);
y = Math.round(y); // round input
srcx = Math.round(srcx);
srcy = Math.round(srcy);
srcw = Math.round(srcw);
srch = Math.round(srch);
var maxWidth = this.bitmap.width;
var maxHeight = this.bitmap.height;
var baseImage = this;
src.scanQuiet(srcx, srcy, srcw, srch, function (sx, sy, idx) {
var xOffset = x + sx - srcx;
var yOffset = y + sy - srcy;
if (xOffset >= 0 && yOffset >= 0 && maxWidth - xOffset > 0 && maxHeight - yOffset > 0) {
var dstIdx = baseImage.getPixelIndex(xOffset, yOffset);
var _src = {
r: this.bitmap.data[idx],
g: this.bitmap.data[idx + 1],
b: this.bitmap.data[idx + 2],
a: this.bitmap.data[idx + 3]
};
var dst = {
r: baseImage.bitmap.data[dstIdx],
g: baseImage.bitmap.data[dstIdx + 1],
b: baseImage.bitmap.data[dstIdx + 2],
a: baseImage.bitmap.data[dstIdx + 3]
};
baseImage.bitmap.data[dstIdx] = (_src.a * (_src.r - dst.r) - dst.r + 255 >> 8) + dst.r;
baseImage.bitmap.data[dstIdx + 1] = (_src.a * (_src.g - dst.g) - dst.g + 255 >> 8) + dst.g;
baseImage.bitmap.data[dstIdx + 2] = (_src.a * (_src.b - dst.b) - dst.b + 255 >> 8) + dst.b;
baseImage.bitmap.data[dstIdx + 3] = this.constructor.limit255(dst.a + _src.a);
}
});
if ((0, _utils.isNodePattern)(cb)) {
cb.call(this, null, this);
}
return this;
}
};
};
exports["default"] = _default;
//# sourceMappingURL=index.js.map

Some files were not shown because too many files have changed in this diff Show More