chore: add jimp dependency, icon padding script, and update configuration
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
import { isNodePattern, throwError } from "@jimp/utils";
|
||||
|
||||
/**
|
||||
* Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default
|
||||
* @param {number} options object
|
||||
* max: A number auto limited between 0 - 255
|
||||
* replace: (optional) A number auto limited between 0 - 255 (default 255)
|
||||
* autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)
|
||||
* @param {number} cb (optional) a callback for when complete
|
||||
* @return {this} this for chaining of methods
|
||||
*/
|
||||
export default (() => ({
|
||||
threshold(_ref, cb) {
|
||||
let {
|
||||
max,
|
||||
replace = 255,
|
||||
autoGreyscale = true
|
||||
} = _ref;
|
||||
if (typeof max !== "number") {
|
||||
return throwError.call(this, "max must be a number", cb);
|
||||
}
|
||||
if (typeof replace !== "number") {
|
||||
return throwError.call(this, "replace must be a number", cb);
|
||||
}
|
||||
if (typeof autoGreyscale !== "boolean") {
|
||||
return throwError.call(this, "autoGreyscale must be a boolean", cb);
|
||||
}
|
||||
max = this.constructor.limit255(max);
|
||||
replace = this.constructor.limit255(replace);
|
||||
if (autoGreyscale) {
|
||||
this.greyscale();
|
||||
}
|
||||
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, (x, y, idx) => {
|
||||
const grey = this.bitmap.data[idx] < max ? this.bitmap.data[idx] : replace;
|
||||
this.bitmap.data[idx] = grey;
|
||||
this.bitmap.data[idx + 1] = grey;
|
||||
this.bitmap.data[idx + 2] = grey;
|
||||
});
|
||||
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","threshold","cb","max","replace","autoGreyscale","call","constructor","limit255","greyscale","scanQuiet","bitmap","width","height","x","y","idx","grey","data"],"sources":["../src/index.js"],"sourcesContent":["import { isNodePattern, throwError } from \"@jimp/utils\";\n\n/**\n * Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default\n * @param {number} options object\n * max: A number auto limited between 0 - 255\n * replace: (optional) A number auto limited between 0 - 255 (default 255)\n * autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)\n * @param {number} cb (optional) a callback for when complete\n * @return {this} this for chaining of methods\n */\nexport default () => ({\n threshold({ max, replace = 255, autoGreyscale = true }, cb) {\n if (typeof max !== \"number\") {\n return throwError.call(this, \"max must be a number\", cb);\n }\n\n if (typeof replace !== \"number\") {\n return throwError.call(this, \"replace must be a number\", cb);\n }\n\n if (typeof autoGreyscale !== \"boolean\") {\n return throwError.call(this, \"autoGreyscale must be a boolean\", cb);\n }\n\n max = this.constructor.limit255(max);\n replace = this.constructor.limit255(replace);\n\n if (autoGreyscale) {\n this.greyscale();\n }\n\n this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, (x, y, idx) => {\n const grey =\n this.bitmap.data[idx] < max ? this.bitmap.data[idx] : replace;\n\n this.bitmap.data[idx] = grey;\n this.bitmap.data[idx + 1] = grey;\n this.bitmap.data[idx + 2] = grey;\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;AACA,gBAAe,OAAO;EACpBC,SAAS,OAA+CC,EAAE,EAAE;IAAA,IAAlD;MAAEC,GAAG;MAAEC,OAAO,GAAG,GAAG;MAAEC,aAAa,GAAG;IAAK,CAAC;IACpD,IAAI,OAAOF,GAAG,KAAK,QAAQ,EAAE;MAC3B,OAAOH,UAAU,CAACM,IAAI,CAAC,IAAI,EAAE,sBAAsB,EAAEJ,EAAE,CAAC;IAC1D;IAEA,IAAI,OAAOE,OAAO,KAAK,QAAQ,EAAE;MAC/B,OAAOJ,UAAU,CAACM,IAAI,CAAC,I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