chore: add jimp dependency, icon padding script, and update configuration
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
import { isNodePattern, throwError } from "@jimp/utils";
|
||||
|
||||
/**
|
||||
* Masks a source image on to this image using average pixel colour. A completely black pixel on the mask will turn a pixel in the image completely transparent.
|
||||
* @param {Jimp} src the source Jimp instance
|
||||
* @param {number} x the horizontal position to blit the image
|
||||
* @param {number} y the vertical position to blit the image
|
||||
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
export default (() => ({
|
||||
mask(src) {
|
||||
let x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
||||
let y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
||||
let cb = arguments.length > 3 ? arguments[3] : undefined;
|
||||
if (!(src instanceof this.constructor)) {
|
||||
return throwError.call(this, "The source must be a Jimp image", cb);
|
||||
}
|
||||
if (typeof x !== "number" || typeof y !== "number") {
|
||||
return throwError.call(this, "x and y must be numbers", cb);
|
||||
}
|
||||
|
||||
// round input
|
||||
x = Math.round(x);
|
||||
y = Math.round(y);
|
||||
const w = this.bitmap.width;
|
||||
const h = this.bitmap.height;
|
||||
const baseImage = this;
|
||||
src.scanQuiet(0, 0, src.bitmap.width, src.bitmap.height, function (sx, sy, idx) {
|
||||
const destX = x + sx;
|
||||
const destY = y + sy;
|
||||
if (destX >= 0 && destY >= 0 && destX < w && destY < h) {
|
||||
const dstIdx = baseImage.getPixelIndex(destX, destY);
|
||||
const {
|
||||
data
|
||||
} = this.bitmap;
|
||||
const avg = (data[idx + 0] + data[idx + 1] + data[idx + 2]) / 3;
|
||||
baseImage.bitmap.data[dstIdx + 3] *= avg / 255;
|
||||
}
|
||||
});
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","names":["isNodePattern","throwError","mask","src","x","y","cb","constructor","call","Math","round","w","bitmap","width","h","height","baseImage","scanQuiet","sx","sy","idx","destX","destY","dstIdx","getPixelIndex","data","avg"],"sources":["../src/index.js"],"sourcesContent":["import { isNodePattern, throwError } from \"@jimp/utils\";\n\n/**\n * Masks a source image on to this image using average pixel colour. A completely black pixel on the mask will turn a pixel in the image completely transparent.\n * @param {Jimp} src the source Jimp instance\n * @param {number} x the horizontal position to blit the image\n * @param {number} y the vertical position to blit the image\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\nexport default () => ({\n mask(src, x = 0, y = 0, cb) {\n if (!(src instanceof this.constructor)) {\n return throwError.call(this, \"The source must be a Jimp image\", cb);\n }\n\n if (typeof x !== \"number\" || typeof y !== \"number\") {\n return throwError.call(this, \"x and y must be numbers\", cb);\n }\n\n // round input\n x = Math.round(x);\n y = Math.round(y);\n\n const w = this.bitmap.width;\n const h = this.bitmap.height;\n const baseImage = this;\n\n src.scanQuiet(\n 0,\n 0,\n src.bitmap.width,\n src.bitmap.height,\n function (sx, sy, idx) {\n const destX = x + sx;\n const destY = y + sy;\n\n if (destX >= 0 && destY >= 0 && destX < w && destY < h) {\n const dstIdx = baseImage.getPixelIndex(destX, destY);\n const { data } = this.bitmap;\n const avg = (data[idx + 0] + data[idx + 1] + data[idx + 2]) / 3;\n\n baseImage.bitmap.data[dstIdx + 3] *= avg / 255;\n }\n }\n );\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n },\n});\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,aAAa;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAe,OAAO;EACpBC,IAAI,CAACC,GAAG,EAAoB;IAAA,IAAlBC,CAAC,uEAAG,CAAC;IAAA,IAAEC,CAAC,uEAAG,CAAC;IAAA,IAAEC,EAAE;IACxB,IAAI,EAA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