Initial commit

This commit is contained in:
robert committed 2025-05-30 18:13:30 +08:00
commit e49726988c
5445 files changed
+1089914

No files matched your search

+36
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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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