Initial commit
This commit is contained in:
commit
e49726988c
5445 files changed
+1089914
No files matched your search
+36
@@ -0,0 +1,36 @@
|
||||
import { JimpClass } from "@jimp/types";
|
||||
import { z } from "zod";
|
||||
declare const ThresholdOptionsSchema: z.ZodObject<{
|
||||
/** A number auto limited between 0 - 255 */
|
||||
max: z.ZodNumber;
|
||||
/** A number auto limited between 0 - 255 (default 255) */
|
||||
replace: z.ZodOptional<z.ZodNumber>;
|
||||
/** A boolean whether to apply greyscale beforehand (default true) */
|
||||
autoGreyscale: z.ZodOptional<z.ZodBoolean>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
max: number;
|
||||
replace?: number | undefined;
|
||||
autoGreyscale?: boolean | undefined;
|
||||
}, {
|
||||
max: number;
|
||||
replace?: number | undefined;
|
||||
autoGreyscale?: boolean | undefined;
|
||||
}>;
|
||||
export type ThresholdOptions = z.infer<typeof ThresholdOptionsSchema>;
|
||||
export declare const methods: {
|
||||
/**
|
||||
* Applies a minimum color threshold to a grayscale image.
|
||||
* Converts image to grayscale by default.
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Jimp } from "jimp";
|
||||
*
|
||||
* const image = await Jimp.read("test/image.png");
|
||||
*
|
||||
* image.threshold({ max: 150 });
|
||||
* ```
|
||||
*/
|
||||
threshold<I extends JimpClass>(image: I, options: ThresholdOptions): I;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,sBAAsB;IAC1B,4CAA4C;;IAE5C,2DAA2D;;IAE3D,sEAAsE;;;;;;;;;;EAEtE,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;OAWG;cACO,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,gBAAgB;CA0BnE,CAAC"}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.methods = void 0;
|
||||
const utils_1 = require("@jimp/utils");
|
||||
const plugin_color_1 = require("@jimp/plugin-color");
|
||||
const zod_1 = require("zod");
|
||||
const ThresholdOptionsSchema = zod_1.z.object({
|
||||
/** A number auto limited between 0 - 255 */
|
||||
max: zod_1.z.number().min(0).max(255),
|
||||
/** A number auto limited between 0 - 255 (default 255) */
|
||||
replace: zod_1.z.number().min(0).max(255).optional(),
|
||||
/** A boolean whether to apply greyscale beforehand (default true) */
|
||||
autoGreyscale: zod_1.z.boolean().optional(),
|
||||
});
|
||||
exports.methods = {
|
||||
/**
|
||||
* Applies a minimum color threshold to a grayscale image.
|
||||
* Converts image to grayscale by default.
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Jimp } from "jimp";
|
||||
*
|
||||
* const image = await Jimp.read("test/image.png");
|
||||
*
|
||||
* image.threshold({ max: 150 });
|
||||
* ```
|
||||
*/
|
||||
threshold(image, options) {
|
||||
let { max, replace = 255,
|
||||
// eslint-disable-next-line prefer-const
|
||||
autoGreyscale = true, } = ThresholdOptionsSchema.parse(options);
|
||||
max = (0, utils_1.limit255)(max);
|
||||
replace = (0, utils_1.limit255)(replace);
|
||||
if (autoGreyscale) {
|
||||
plugin_color_1.methods.greyscale(image);
|
||||
}
|
||||
image.scan((_, __, idx) => {
|
||||
const grey = image.bitmap.data[idx] < max ? image.bitmap.data[idx] : replace;
|
||||
image.bitmap.data[idx] = grey;
|
||||
image.bitmap.data[idx + 1] = grey;
|
||||
image.bitmap.data[idx + 2] = grey;
|
||||
});
|
||||
return image;
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
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AC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YAC9B,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;YAClC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import { JimpClass } from "@jimp/types";
|
||||
import { z } from "zod";
|
||||
declare const ThresholdOptionsSchema: z.ZodObject<{
|
||||
/** A number auto limited between 0 - 255 */
|
||||
max: z.ZodNumber;
|
||||
/** A number auto limited between 0 - 255 (default 255) */
|
||||
replace: z.ZodOptional<z.ZodNumber>;
|
||||
/** A boolean whether to apply greyscale beforehand (default true) */
|
||||
autoGreyscale: z.ZodOptional<z.ZodBoolean>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
max: number;
|
||||
replace?: number | undefined;
|
||||
autoGreyscale?: boolean | undefined;
|
||||
}, {
|
||||
max: number;
|
||||
replace?: number | undefined;
|
||||
autoGreyscale?: boolean | undefined;
|
||||
}>;
|
||||
export type ThresholdOptions = z.infer<typeof ThresholdOptionsSchema>;
|
||||
export declare const methods: {
|
||||
/**
|
||||
* Applies a minimum color threshold to a grayscale image.
|
||||
* Converts image to grayscale by default.
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Jimp } from "jimp";
|
||||
*
|
||||
* const image = await Jimp.read("test/image.png");
|
||||
*
|
||||
* image.threshold({ max: 150 });
|
||||
* ```
|
||||
*/
|
||||
threshold<I extends JimpClass>(image: I, options: ThresholdOptions): I;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,sBAAsB;IAC1B,4CAA4C;;IAE5C,2DAA2D;;IAE3D,sEAAsE;;;;;;;;;;EAEtE,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;OAWG;cACO,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,gBAAgB;CA0BnE,CAAC"}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import { limit255 } from "@jimp/utils";
|
||||
import { methods as color } from "@jimp/plugin-color";
|
||||
import { z } from "zod";
|
||||
const ThresholdOptionsSchema = z.object({
|
||||
/** A number auto limited between 0 - 255 */
|
||||
max: z.number().min(0).max(255),
|
||||
/** A number auto limited between 0 - 255 (default 255) */
|
||||
replace: z.number().min(0).max(255).optional(),
|
||||
/** A boolean whether to apply greyscale beforehand (default true) */
|
||||
autoGreyscale: z.boolean().optional(),
|
||||
});
|
||||
export const methods = {
|
||||
/**
|
||||
* Applies a minimum color threshold to a grayscale image.
|
||||
* Converts image to grayscale by default.
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Jimp } from "jimp";
|
||||
*
|
||||
* const image = await Jimp.read("test/image.png");
|
||||
*
|
||||
* image.threshold({ max: 150 });
|
||||
* ```
|
||||
*/
|
||||
threshold(image, options) {
|
||||
let { max, replace = 255,
|
||||
// eslint-disable-next-line prefer-const
|
||||
autoGreyscale = true, } = ThresholdOptionsSchema.parse(options);
|
||||
max = limit255(max);
|
||||
replace = limit255(replace);
|
||||
if (autoGreyscale) {
|
||||
color.greyscale(image);
|
||||
}
|
||||
image.scan((_, __, idx) => {
|
||||
const grey = image.bitmap.data[idx] < max ? image.bitmap.data[idx] : replace;
|
||||
image.bitmap.data[idx] = grey;
|
||||
image.bitmap.data[idx + 1] = grey;
|
||||
image.bitmap.data[idx + 2] = grey;
|
||||
});
|
||||
return image;
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,4CAA4C;IAC5C,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAC/B,2DAA2D;IAC3D,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;IAC9C,sEAAsE;IACtE,aAAa,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB;;;;;;;;;;;OAWG;IACH,SAAS,CAAsB,KAAQ,EAAE,OAAyB;QAChE,IAAI,EACF,GAAG,EACH,OAAO,GAAG,GAAG;QACb,wCAAwC;QACxC,aAAa,GAAG,IAAI,GACrB,GAAG,sBAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE1C,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QACpB,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QAE5B,IAAI,aAAa,EAAE,CAAC;YAClB,KAAK,CAAC,SAAS,CAAC,KAAK,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