@jimp/plugin-threshold 0.22.12 → 1.0.2--canary.4e85de0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.cjs ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import("eslint").Linter.Config} */
2
+ module.exports = {
3
+ root: true,
4
+ extends: [require.resolve("@jimp/config-eslint/base.js")],
5
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "../src",
5
+ "target": "es2022",
6
+ "module": "nodenext",
7
+ "moduleResolution": "nodenext"
8
+ }
9
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "./build.json",
3
+ "include": [
4
+ "../src/**/*.ts",
5
+ "../src/**/*.cts",
6
+ "../src/**/*.tsx"
7
+ ],
8
+ "exclude": [
9
+ "../**/*.test.ts",
10
+ "../src/**/*.mts"
11
+ ],
12
+ "compilerOptions": {
13
+ "outDir": "../.tshy-build/commonjs"
14
+ }
15
+ }
package/.tshy/esm.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./build.json",
3
+ "include": [
4
+ "../src/**/*.ts",
5
+ "../src/**/*.mts",
6
+ "../src/**/*.tsx"
7
+ ],
8
+ "exclude": [
9
+ "../**/*.test.ts"
10
+ ],
11
+ "compilerOptions": {
12
+ "outDir": "../.tshy-build/esm"
13
+ }
14
+ }
@@ -0,0 +1,4 @@
1
+
2
+ > @jimp/plugin-threshold@1.0.0 build /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
3
+ > tshy
4
+
@@ -0,0 +1,4 @@
1
+
2
+ > @jimp/plugin-threshold@1.0.0 lint /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
3
+ > eslint .
4
+
@@ -0,0 +1,162 @@
1
+
2
+ > @jimp/plugin-threshold@1.0.0 test:browser /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
3
+ > vitest --config vitest.config.browser.mjs "--watch=false"
4
+
5
+
6
+  RUN  v1.4.0 /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
7
+  Browser runner started at http://localhost:5173/
8
+
9
+ [?25l · src/index.test.ts (1)
10
+ · Threshold (1)
11
+ · defines default threshold for lighter backgrounds
12
+ [?25l[?25l[?25l[?25l[?25l[?25l[?25l ❯ src/index.test.ts (1)
13
+ ❯ Threshold (1)
14
+ ⠙ defines default threshold for lighter backgrounds
15
+ [?25l ❯ src/index.test.ts (1)
16
+ ❯ Threshold (1)
17
+ ⠹ defines default threshold for lighter backgrounds
18
+ [?25l ❯ src/index.test.ts (1)
19
+ ❯ Threshold (1)
20
+ ⠸ defines default threshold for lighter backgrounds
21
+ [?25l ❯ src/index.test.ts (1)
22
+ ❯ Threshold (1)
23
+ ⠼ defines default threshold for lighter backgrounds
24
+ [?25l ❯ src/index.test.ts (1)
25
+ ❯ Threshold (1)
26
+ ⠴ defines default threshold for lighter backgrounds
27
+ [?25l ❯ src/index.test.ts (1)
28
+ ❯ Threshold (1)
29
+ ⠦ defines default threshold for lighter backgrounds
30
+ [?25l ❯ src/index.test.ts (1)
31
+ ❯ Threshold (1)
32
+ ⠧ defines default threshold for lighter backgrounds
33
+ [?25l ❯ src/index.test.ts (1)
34
+ ❯ Threshold (1)
35
+ ⠇ defines default threshold for lighter backgrounds
36
+ [?25l ❯ src/index.test.ts (1)
37
+ ❯ Threshold (1)
38
+ ⠏ defines default threshold for lighter backgrounds
39
+ [?25l ❯ src/index.test.ts (1)
40
+ ❯ Threshold (1)
41
+ ⠋ defines default threshold for lighter backgrounds
42
+ [?25l ❯ src/index.test.ts (1)
43
+ ❯ Threshold (1)
44
+ ⠙ defines default threshold for lighter backgrounds
45
+ [?25l ❯ src/index.test.ts (1)
46
+ ❯ Threshold (1)
47
+ ⠹ defines default threshold for lighter backgrounds
48
+ [?25l ❯ src/index.test.ts (1)
49
+ ❯ Threshold (1)
50
+ ⠸ defines default threshold for lighter backgrounds
51
+ [?25l ❯ src/index.test.ts (1)
52
+ ❯ Threshold (1)
53
+ ⠼ defines default threshold for lighter backgrounds
54
+ [?25l ❯ src/index.test.ts (1)
55
+ ❯ Threshold (1)
56
+ ⠴ defines default threshold for lighter backgrounds
57
+ [?25l ❯ src/index.test.ts (1)
58
+ ❯ Threshold (1)
59
+ ⠦ defines default threshold for lighter backgrounds
60
+ [?25l ❯ src/index.test.ts (1)
61
+ ❯ Threshold (1)
62
+ ⠧ defines default threshold for lighter backgrounds
63
+ [?25l ❯ src/index.test.ts (1)
64
+ ❯ Threshold (1)
65
+ ⠇ defines default threshold for lighter backgrounds
66
+ [?25l ❯ src/index.test.ts (1)
67
+ ❯ Threshold (1)
68
+ ⠏ defines default threshold for lighter backgrounds
69
+ [?25l ❯ src/index.test.ts (1)
70
+ ❯ Threshold (1)
71
+ ⠋ defines default threshold for lighter backgrounds
72
+ [?25l ❯ src/index.test.ts (1)
73
+ ❯ Threshold (1)
74
+ ⠙ defines default threshold for lighter backgrounds
75
+ [?25l ❯ src/index.test.ts (1)
76
+ ❯ Threshold (1)
77
+ ⠹ defines default threshold for lighter backgrounds
78
+ [?25l ❯ src/index.test.ts (1)
79
+ ❯ Threshold (1)
80
+ ⠸ defines default threshold for lighter backgrounds
81
+ [?25l ❯ src/index.test.ts (1)
82
+ ❯ Threshold (1)
83
+ ⠼ defines default threshold for lighter backgrounds
84
+ [?25l ❯ src/index.test.ts (1)
85
+ ❯ Threshold (1)
86
+ ⠴ defines default threshold for lighter backgrounds
87
+ [?25l ❯ src/index.test.ts (1)
88
+ ❯ Threshold (1)
89
+ ⠦ defines default threshold for lighter backgrounds
90
+ [?25l ❯ src/index.test.ts (1)
91
+ ❯ Threshold (1)
92
+ ⠧ defines default threshold for lighter backgrounds
93
+ [?25l · src/index.test.ts (1)
94
+ · Threshold (1)
95
+ · defines default threshold for lighter backgrounds
96
+ [?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l ❯ src/index.test.ts (1)
97
+ ❯ Threshold (1)
98
+ ⠙ defines default threshold for lighter backgrounds
99
+ [?25l ❯ src/index.test.ts (1)
100
+ ❯ Threshold (1)
101
+ ⠹ defines default threshold for lighter backgrounds
102
+ [?25l ❯ src/index.test.ts (1)
103
+ ❯ Threshold (1)
104
+ ⠸ defines default threshold for lighter backgrounds
105
+ [?25l ❯ src/index.test.ts (1)
106
+ ❯ Threshold (1)
107
+ ⠼ defines default threshold for lighter backgrounds
108
+ [?25l ❯ src/index.test.ts (1)
109
+ ❯ Threshold (1)
110
+ ⠴ defines default threshold for lighter backgrounds
111
+ [?25l ❯ src/index.test.ts (1)
112
+ ❯ Threshold (1)
113
+ ⠦ defines default threshold for lighter backgrounds
114
+ [?25l ❯ src/index.test.ts (1)
115
+ ❯ Threshold (1)
116
+ ⠧ defines default threshold for lighter backgrounds
117
+ [?25l ❯ src/index.test.ts (1)
118
+ ❯ Threshold (1)
119
+ ⠇ defines default threshold for lighter backgrounds
120
+ [?25l ❯ src/index.test.ts (1)
121
+ ❯ Threshold (1)
122
+ ⠏ defines default threshold for lighter backgrounds
123
+ [?25l ❯ src/index.test.ts (1)
124
+ ❯ Threshold (1)
125
+ ⠋ defines default threshold for lighter backgrounds
126
+ [?25l ❯ src/index.test.ts (1)
127
+ ❯ Threshold (1)
128
+ ⠙ defines default threshold for lighter backgrounds
129
+ [?25l ❯ src/index.test.ts (1)
130
+ ❯ Threshold (1)
131
+ ⠹ defines default threshold for lighter backgrounds
132
+ [?25l ❯ src/index.test.ts (1)
133
+ ❯ Threshold (1)
134
+ ⠸ defines default threshold for lighter backgrounds
135
+ [?25l ❯ src/index.test.ts (1)
136
+ ❯ Threshold (1)
137
+ ⠼ defines default threshold for lighter backgrounds
138
+ [?25l ❯ src/index.test.ts (1)
139
+ ❯ Threshold (1)
140
+ ⠴ defines default threshold for lighter backgrounds
141
+ [?25l ❯ src/index.test.ts (1)
142
+ ❯ Threshold (1)
143
+ ⠦ defines default threshold for lighter backgrounds
144
+ [?25l ❯ src/index.test.ts (1)
145
+ ❯ Threshold (1)
146
+ ⠧ defines default threshold for lighter backgrounds
147
+ [?25l ❯ src/index.test.ts (1)
148
+ ❯ Threshold (1)
149
+ ⠇ defines default threshold for lighter backgrounds
150
+ [?25l ✓ src/index.test.ts (1) 433ms
151
+ ✓ Threshold (1) 433ms
152
+ ✓ defines default threshold for lighter backgrounds 432ms
153
+  ✓ src/index.test.ts (1) 433ms
154
+ ✓ Threshold (1) 433ms
155
+ ✓ defines default threshold for lighter backgrounds 432ms
156
+
157
+  Test Files  1 passed (1)
158
+  Tests  1 passed (1)
159
+  Start at  14:34:41
160
+  Duration  1.80s (transform 0ms, setup 1ms, collect 51ms, tests 433ms, environment 0ms, prepare 0ms)
161
+
162
+ [?25h[?25h
@@ -0,0 +1,92 @@
1
+
2
+ > @jimp/plugin-threshold@1.0.0 test /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
3
+ > vitest "--watch=false" "--no-cache"
4
+
5
+
6
+  RUN  v1.4.0 /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
7
+
8
+ [?25l · src/index.test.ts (1)
9
+ · Threshold (1)
10
+ · defines default threshold for lighter backgrounds
11
+ [?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l ❯ src/index.test.ts (1)
12
+ ❯ Threshold (1)
13
+ ⠙ defines default threshold for lighter backgrounds
14
+ [?25l ❯ src/index.test.ts (1)
15
+ ❯ Threshold (1)
16
+ ⠹ defines default threshold for lighter backgrounds
17
+ [?25l ❯ src/index.test.ts (1)
18
+ ❯ Threshold (1)
19
+ ⠸ defines default threshold for lighter backgrounds
20
+ [?25l ❯ src/index.test.ts (1)
21
+ ❯ Threshold (1)
22
+ ⠼ defines default threshold for lighter backgrounds
23
+ [?25l ❯ src/index.test.ts (1)
24
+ ❯ Threshold (1)
25
+ ⠴ defines default threshold for lighter backgrounds
26
+ [?25l ❯ src/index.test.ts (1)
27
+ ❯ Threshold (1)
28
+ ⠦ defines default threshold for lighter backgrounds
29
+ [?25l ❯ src/index.test.ts (1)
30
+ ❯ Threshold (1)
31
+ ⠧ defines default threshold for lighter backgrounds
32
+ [?25l ❯ src/index.test.ts (1)
33
+ ❯ Threshold (1)
34
+ ⠇ defines default threshold for lighter backgrounds
35
+ [?25l ❯ src/index.test.ts (1)
36
+ ❯ Threshold (1)
37
+ ⠏ defines default threshold for lighter backgrounds
38
+ [?25l ❯ src/index.test.ts (1)
39
+ ❯ Threshold (1)
40
+ ⠋ defines default threshold for lighter backgrounds
41
+ [?25l ❯ src/index.test.ts (1)
42
+ ❯ Threshold (1)
43
+ ⠙ defines default threshold for lighter backgrounds
44
+ [?25l ❯ src/index.test.ts (1)
45
+ ❯ Threshold (1)
46
+ ⠹ defines default threshold for lighter backgrounds
47
+ [?25l ❯ src/index.test.ts (1)
48
+ ❯ Threshold (1)
49
+ ⠸ defines default threshold for lighter backgrounds
50
+ [?25l ❯ src/index.test.ts (1)
51
+ ❯ Threshold (1)
52
+ ⠼ defines default threshold for lighter backgrounds
53
+ [?25l ❯ src/index.test.ts (1)
54
+ ❯ Threshold (1)
55
+ ⠴ defines default threshold for lighter backgrounds
56
+ [?25l ❯ src/index.test.ts (1)
57
+ ❯ Threshold (1)
58
+ ⠦ defines default threshold for lighter backgrounds
59
+ [?25l ❯ src/index.test.ts (1)
60
+ ❯ Threshold (1)
61
+ ⠧ defines default threshold for lighter backgrounds
62
+ [?25l ❯ src/index.test.ts (1)
63
+ ❯ Threshold (1)
64
+ ⠇ defines default threshold for lighter backgrounds
65
+ [?25l ❯ src/index.test.ts (1)
66
+ ❯ Threshold (1)
67
+ ⠏ defines default threshold for lighter backgrounds
68
+ [?25l ❯ src/index.test.ts (1)
69
+ ❯ Threshold (1)
70
+ ⠋ defines default threshold for lighter backgrounds
71
+ [?25l ❯ src/index.test.ts (1)
72
+ ❯ Threshold (1)
73
+ ⠙ defines default threshold for lighter backgrounds
74
+ [?25l ❯ src/index.test.ts (1)
75
+ ❯ Threshold (1)
76
+ ⠹ defines default threshold for lighter backgrounds
77
+ [?25l ❯ src/index.test.ts (1)
78
+ ❯ Threshold (1)
79
+ ⠸ defines default threshold for lighter backgrounds
80
+ [?25l ✓ src/index.test.ts (1) 550ms
81
+ ✓ Threshold (1) 548ms
82
+ ✓ defines default threshold for lighter backgrounds 548ms
83
+ [?25l ✓ src/index.test.ts (1) 550ms
84
+ ✓ Threshold (1) 548ms
85
+ ✓ defines default threshold for lighter backgrounds 548ms
86
+
87
+  Test Files  1 passed (1)
88
+  Tests  1 passed (1)
89
+  Start at  14:26:15
90
+  Duration  888ms (transform 124ms, setup 0ms, collect 149ms, tests 550ms, environment 0ms, prepare 50ms)
91
+
92
+ [?25h[?25h
@@ -0,0 +1,36 @@
1
+ import { JimpClass } from "@jimp/types";
2
+ import { z } from "zod";
3
+ declare const ThresholdOptionsSchema: z.ZodObject<{
4
+ /** A number auto limited between 0 - 255 */
5
+ max: z.ZodNumber;
6
+ /** A number auto limited between 0 - 255 (default 255) */
7
+ replace: z.ZodOptional<z.ZodNumber>;
8
+ /** A boolean whether to apply greyscale beforehand (default true) */
9
+ autoGreyscale: z.ZodOptional<z.ZodBoolean>;
10
+ }, "strip", z.ZodTypeAny, {
11
+ max: number;
12
+ replace?: number | undefined;
13
+ autoGreyscale?: boolean | undefined;
14
+ }, {
15
+ max: number;
16
+ replace?: number | undefined;
17
+ autoGreyscale?: boolean | undefined;
18
+ }>;
19
+ export type ThresholdOptions = z.infer<typeof ThresholdOptionsSchema>;
20
+ export declare const methods: {
21
+ /**
22
+ * Applies a minimum color threshold to a grayscale image.
23
+ * Converts image to grayscale by default.
24
+ * @example
25
+ * ```ts
26
+ * import { Jimp } from "jimp";
27
+ *
28
+ * const image = await Jimp.read("test/image.png");
29
+ *
30
+ * image.threshold({ max: 150 });
31
+ * ```
32
+ */
33
+ threshold<I extends JimpClass>(image: I, options: ThresholdOptions): I;
34
+ };
35
+ export {};
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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;0CACmC,CAAC,WAAW,gBAAgB;CA0BnE,CAAC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.methods = void 0;
4
+ const utils_1 = require("@jimp/utils");
5
+ const plugin_color_1 = require("@jimp/plugin-color");
6
+ const zod_1 = require("zod");
7
+ const ThresholdOptionsSchema = zod_1.z.object({
8
+ /** A number auto limited between 0 - 255 */
9
+ max: zod_1.z.number().min(0).max(255),
10
+ /** A number auto limited between 0 - 255 (default 255) */
11
+ replace: zod_1.z.number().min(0).max(255).optional(),
12
+ /** A boolean whether to apply greyscale beforehand (default true) */
13
+ autoGreyscale: zod_1.z.boolean().optional(),
14
+ });
15
+ exports.methods = {
16
+ /**
17
+ * Applies a minimum color threshold to a grayscale image.
18
+ * Converts image to grayscale by default.
19
+ * @example
20
+ * ```ts
21
+ * import { Jimp } from "jimp";
22
+ *
23
+ * const image = await Jimp.read("test/image.png");
24
+ *
25
+ * image.threshold({ max: 150 });
26
+ * ```
27
+ */
28
+ threshold(image, options) {
29
+ let { max, replace = 255,
30
+ // eslint-disable-next-line prefer-const
31
+ autoGreyscale = true, } = ThresholdOptionsSchema.parse(options);
32
+ max = (0, utils_1.limit255)(max);
33
+ replace = (0, utils_1.limit255)(replace);
34
+ if (autoGreyscale) {
35
+ plugin_color_1.methods.greyscale(image);
36
+ }
37
+ image.scan((_, __, idx) => {
38
+ const grey = image.bitmap.data[idx] < max ? image.bitmap.data[idx] : replace;
39
+ image.bitmap.data[idx] = grey;
40
+ image.bitmap.data[idx + 1] = grey;
41
+ image.bitmap.data[idx + 2] = grey;
42
+ });
43
+ return image;
44
+ },
45
+ };
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,uCAAuC;AACvC,qDAAsD;AACtD,6BAAwB;AAExB,MAAM,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IACtC,4CAA4C;IAC5C,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAC/B,2DAA2D;IAC3D,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;IAC9C,sEAAsE;IACtE,aAAa,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAC;AAIU,QAAA,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,IAAA,gBAAQ,EAAC,GAAG,CAAC,CAAC;QACpB,OAAO,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAC;QAE5B,IAAI,aAAa,EAAE,CAAC;YAClB,sBAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;YACxB,MAAM,IAAI,GACR,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YAEpE,KAAK,CAAC,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"}
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "commonjs",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "sideEffects": false
7
+ }
@@ -0,0 +1,36 @@
1
+ import { JimpClass } from "@jimp/types";
2
+ import { z } from "zod";
3
+ declare const ThresholdOptionsSchema: z.ZodObject<{
4
+ /** A number auto limited between 0 - 255 */
5
+ max: z.ZodNumber;
6
+ /** A number auto limited between 0 - 255 (default 255) */
7
+ replace: z.ZodOptional<z.ZodNumber>;
8
+ /** A boolean whether to apply greyscale beforehand (default true) */
9
+ autoGreyscale: z.ZodOptional<z.ZodBoolean>;
10
+ }, "strip", z.ZodTypeAny, {
11
+ max: number;
12
+ replace?: number | undefined;
13
+ autoGreyscale?: boolean | undefined;
14
+ }, {
15
+ max: number;
16
+ replace?: number | undefined;
17
+ autoGreyscale?: boolean | undefined;
18
+ }>;
19
+ export type ThresholdOptions = z.infer<typeof ThresholdOptionsSchema>;
20
+ export declare const methods: {
21
+ /**
22
+ * Applies a minimum color threshold to a grayscale image.
23
+ * Converts image to grayscale by default.
24
+ * @example
25
+ * ```ts
26
+ * import { Jimp } from "jimp";
27
+ *
28
+ * const image = await Jimp.read("test/image.png");
29
+ *
30
+ * image.threshold({ max: 150 });
31
+ * ```
32
+ */
33
+ threshold<I extends JimpClass>(image: I, options: ThresholdOptions): I;
34
+ };
35
+ export {};
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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;0CACmC,CAAC,WAAW,gBAAgB;CA0BnE,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { limit255 } from "@jimp/utils";
2
+ import { methods as color } from "@jimp/plugin-color";
3
+ import { z } from "zod";
4
+ const ThresholdOptionsSchema = z.object({
5
+ /** A number auto limited between 0 - 255 */
6
+ max: z.number().min(0).max(255),
7
+ /** A number auto limited between 0 - 255 (default 255) */
8
+ replace: z.number().min(0).max(255).optional(),
9
+ /** A boolean whether to apply greyscale beforehand (default true) */
10
+ autoGreyscale: z.boolean().optional(),
11
+ });
12
+ export const methods = {
13
+ /**
14
+ * Applies a minimum color threshold to a grayscale image.
15
+ * Converts image to grayscale by default.
16
+ * @example
17
+ * ```ts
18
+ * import { Jimp } from "jimp";
19
+ *
20
+ * const image = await Jimp.read("test/image.png");
21
+ *
22
+ * image.threshold({ max: 150 });
23
+ * ```
24
+ */
25
+ threshold(image, options) {
26
+ let { max, replace = 255,
27
+ // eslint-disable-next-line prefer-const
28
+ autoGreyscale = true, } = ThresholdOptionsSchema.parse(options);
29
+ max = limit255(max);
30
+ replace = limit255(replace);
31
+ if (autoGreyscale) {
32
+ color.greyscale(image);
33
+ }
34
+ image.scan((_, __, idx) => {
35
+ const grey = image.bitmap.data[idx] < max ? image.bitmap.data[idx] : replace;
36
+ image.bitmap.data[idx] = grey;
37
+ image.bitmap.data[idx + 1] = grey;
38
+ image.bitmap.data[idx + 2] = grey;
39
+ });
40
+ return image;
41
+ },
42
+ };
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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,CAAC,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;YACxB,MAAM,IAAI,GACR,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YAEpE,KAAK,CAAC,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"}
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "module",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "sideEffects": false
7
+ }
package/package.json CHANGED
@@ -1,42 +1,65 @@
1
1
  {
2
2
  "name": "@jimp/plugin-threshold",
3
- "version": "0.22.12",
4
- "description": "Lightens an image.",
5
- "main": "dist/index.js",
6
- "module": "es/index.js",
3
+ "version": "1.0.2--canary.4e85de0.0",
7
4
  "repository": "jimp-dev/jimp",
8
- "types": "index.d.ts",
9
5
  "scripts": {
10
- "test": "cross-env BABEL_ENV=test mocha --require @babel/register --recursive test --extension js",
11
- "test:watch": "npm run test -- --reporter min --watch",
12
- "test:coverage": "nyc npm run test",
13
- "build": "npm run build:node:production && npm run build:module",
14
- "build:watch": "npm run build:node:debug -- -- --watch --verbose",
15
- "build:debug": "npm run build:node:debug",
16
- "build:module": "cross-env BABEL_ENV=module babel src -d es --source-maps --config-file ../../babel.config.js",
17
- "build:node": "babel src -d dist --source-maps --config-file ../../babel.config.js",
18
- "build:node:debug": "cross-env BABEL_ENV=development npm run build:node",
19
- "build:node:production": "cross-env BABEL_ENV=production npm run build:node"
6
+ "lint": "eslint .",
7
+ "test": "vitest",
8
+ "test:browser": "vitest --config vitest.config.browser.mjs",
9
+ "build": "tshy",
10
+ "dev": "tshy --watch"
20
11
  },
21
- "author": "",
12
+ "author": "Andrew Lisowski <lisowski54@gmail.com>",
22
13
  "license": "MIT",
14
+ "devDependencies": {
15
+ "@jimp/config-eslint": "1.0.2--canary.4e85de0.0",
16
+ "@jimp/config-typescript": "1.0.2--canary.4e85de0.0",
17
+ "@jimp/config-vitest": "1.0.2--canary.4e85de0.0",
18
+ "@jimp/js-jpeg": "1.0.2--canary.4e85de0.0",
19
+ "@jimp/test-utils": "1.0.2--canary.4e85de0.0",
20
+ "@vitest/browser": "^1.4.0",
21
+ "eslint": "^8.57.0",
22
+ "tshy": "^1.12.0",
23
+ "typescript": "^5.4.2",
24
+ "vite-plugin-node-polyfills": "^0.21.0",
25
+ "vitest": "^1.4.0"
26
+ },
23
27
  "dependencies": {
24
- "@jimp/utils": "^0.22.12"
28
+ "@jimp/core": "1.0.2--canary.4e85de0.0",
29
+ "@jimp/plugin-color": "1.0.2--canary.4e85de0.0",
30
+ "@jimp/plugin-hash": "1.0.2--canary.4e85de0.0",
31
+ "@jimp/types": "1.0.2--canary.4e85de0.0",
32
+ "@jimp/utils": "1.0.2--canary.4e85de0.0",
33
+ "zod": "^3.22.4"
25
34
  },
26
- "peerDependencies": {
27
- "@jimp/custom": ">=0.3.5",
28
- "@jimp/plugin-color": ">=0.8.0",
29
- "@jimp/plugin-resize": ">=0.8.0"
35
+ "tshy": {
36
+ "exclude": [
37
+ "**/*.test.ts"
38
+ ],
39
+ "exports": {
40
+ "./package.json": "./package.json",
41
+ ".": "./src/index.ts"
42
+ }
30
43
  },
31
- "devDependencies": {
32
- "@jimp/custom": "^0.22.12",
33
- "@jimp/jpeg": "^0.22.12",
34
- "@jimp/plugin-color": "^0.22.12",
35
- "@jimp/plugin-resize": "^0.22.12",
36
- "@jimp/test-utils": "^0.22.12"
44
+ "exports": {
45
+ "./package.json": "./package.json",
46
+ ".": {
47
+ "import": {
48
+ "types": "./dist/esm/index.d.ts",
49
+ "default": "./dist/esm/index.js"
50
+ },
51
+ "require": {
52
+ "types": "./dist/commonjs/index.d.ts",
53
+ "default": "./dist/commonjs/index.js"
54
+ }
55
+ }
37
56
  },
57
+ "main": "./dist/commonjs/index.js",
58
+ "types": "./dist/commonjs/index.d.ts",
59
+ "type": "module",
38
60
  "publishConfig": {
39
61
  "access": "public"
40
62
  },
41
- "gitHead": "a4a8d6364bbf97629749e196f3b0a4c94c9a7abc"
63
+ "sideEffects": false,
64
+ "gitHead": "4e85de0027857bbc7b06ecfd8b98e5d6898fbb94"
42
65
  }
@@ -0,0 +1,23 @@
1
+ import { expect, test, describe } from "vitest";
2
+ import "@jimp/test-utils";
3
+
4
+ import jpeg from "@jimp/js-jpeg";
5
+ import { methods as hash } from "@jimp/plugin-hash";
6
+ import { createJimp } from "@jimp/core";
7
+
8
+ import { methods as threshold } from "./index.js";
9
+ import { getTestImagePath } from "@jimp/test-utils";
10
+
11
+ const jimp = createJimp({ formats: [jpeg], plugins: [threshold, hash] });
12
+
13
+ describe("Threshold", () => {
14
+ test("defines default threshold for lighter backgrounds", async () => {
15
+ const testImage = await jimp.read(getTestImagePath("hands.jpg"));
16
+ const expectedImage = await jimp.read(
17
+ getTestImagePath("hands_mx200_rp255.jpg")
18
+ );
19
+ const output = testImage.threshold({ max: 200, replace: 255 }).hash();
20
+
21
+ expect(output).toStrictEqual(expectedImage.hash());
22
+ });
23
+ });
package/src/index.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { JimpClass } from "@jimp/types";
2
+ import { limit255 } from "@jimp/utils";
3
+ import { methods as color } from "@jimp/plugin-color";
4
+ import { z } from "zod";
5
+
6
+ const ThresholdOptionsSchema = z.object({
7
+ /** A number auto limited between 0 - 255 */
8
+ max: z.number().min(0).max(255),
9
+ /** A number auto limited between 0 - 255 (default 255) */
10
+ replace: z.number().min(0).max(255).optional(),
11
+ /** A boolean whether to apply greyscale beforehand (default true) */
12
+ autoGreyscale: z.boolean().optional(),
13
+ });
14
+
15
+ export type ThresholdOptions = z.infer<typeof ThresholdOptionsSchema>;
16
+
17
+ export const methods = {
18
+ /**
19
+ * Applies a minimum color threshold to a grayscale image.
20
+ * Converts image to grayscale by default.
21
+ * @example
22
+ * ```ts
23
+ * import { Jimp } from "jimp";
24
+ *
25
+ * const image = await Jimp.read("test/image.png");
26
+ *
27
+ * image.threshold({ max: 150 });
28
+ * ```
29
+ */
30
+ threshold<I extends JimpClass>(image: I, options: ThresholdOptions) {
31
+ let {
32
+ max,
33
+ replace = 255,
34
+ // eslint-disable-next-line prefer-const
35
+ autoGreyscale = true,
36
+ } = ThresholdOptionsSchema.parse(options);
37
+
38
+ max = limit255(max);
39
+ replace = limit255(replace);
40
+
41
+ if (autoGreyscale) {
42
+ color.greyscale(image);
43
+ }
44
+
45
+ image.scan((_, __, idx) => {
46
+ const grey =
47
+ image.bitmap.data[idx]! < max ? image.bitmap.data[idx]! : replace;
48
+
49
+ image.bitmap.data[idx] = grey;
50
+ image.bitmap.data[idx + 1] = grey;
51
+ image.bitmap.data[idx + 2] = grey;
52
+ });
53
+
54
+ return image;
55
+ },
56
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "@jimp/config-typescript/base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ }
6
+ }
@@ -0,0 +1,3 @@
1
+ import config from "@jimp/config-vitest/browser";
2
+
3
+ export default config;
package/CHANGELOG.md DELETED
@@ -1,97 +0,0 @@
1
- # v0.22.1 (Mon Feb 06 2023)
2
-
3
- #### 🏠 Internal
4
-
5
- - rename master to main [#1169](https://github.com/jimp-dev/jimp/pull/1169) ([@hipstersmoothie](https://github.com/hipstersmoothie))
6
-
7
- #### Authors: 1
8
-
9
- - Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
10
-
11
- ---
12
-
13
- # v0.22.0 (Mon Feb 06 2023)
14
-
15
- #### 🏠 Internal
16
-
17
- - switch from should to expect [#1163](https://github.com/jimp-dev/jimp/pull/1163) ([@hipstersmoothie](https://github.com/hipstersmoothie))
18
- - Change test matching strategy to include all test files [#1161](https://github.com/jimp-dev/jimp/pull/1161) ([@danielholmes](https://github.com/danielholmes))
19
-
20
- #### Authors: 2
21
-
22
- - Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
23
- - Daniel Holmes ([@danielholmes](https://github.com/danielholmes))
24
-
25
- ---
26
-
27
- # v0.21.0 (Sun Feb 05 2023)
28
-
29
- ### Release Notes
30
-
31
- #### Babel Refactor ([#1149](https://github.com/jimp-dev/jimp/pull/1149))
32
-
33
- Marking this as a "breaking release" because it might change what deps need to be installed.
34
-
35
- All modules should be exported as valid cjs and esm
36
-
37
- ![CleanShot 2023-02-04 at 18 19 27](https://user-images.githubusercontent.com/1192452/216798157-664cc430-7846-432d-84cf-26e8d8ba9e10.png)
38
-
39
- ---
40
-
41
- #### 💥 Breaking Change
42
-
43
- - Babel Refactor [#1149](https://github.com/jimp-dev/jimp/pull/1149) ([@hipstersmoothie](https://github.com/hipstersmoothie))
44
-
45
- #### Authors: 1
46
-
47
- - Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
48
-
49
- ---
50
-
51
- # v0.16.3 (Sat Feb 04 2023)
52
-
53
- #### ⚠️ Pushed to `main`
54
-
55
- - upgrade prettier ([@hipstersmoothie](https://github.com/hipstersmoothie))
56
-
57
- #### Authors: 1
58
-
59
- - Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
60
-
61
- ---
62
-
63
- # v0.11.0 (Fri May 15 2020)
64
-
65
- #### 🚀 Enhancement
66
-
67
- - Removed Core-JS as a dependency. [#882](https://github.com/oliver-moran/jimp/pull/882) ([@EricRabil](https://github.com/EricRabil))
68
-
69
- #### Authors: 1
70
-
71
- - Eric Rabil ([@EricRabil](https://github.com/EricRabil))
72
-
73
- ---
74
-
75
- # v0.9.7 (Fri Mar 27 2020)
76
-
77
- #### 🐛 Bug Fix
78
-
79
- - Relax version range of plugin-threshold peerDependencies [#859](https://github.com/oliver-moran/jimp/pull/859) ([@pasieronen](https://github.com/pasieronen))
80
-
81
- #### Authors: 1
82
-
83
- - Pasi Eronen ([@pasieronen](https://github.com/pasieronen))
84
-
85
- ---
86
-
87
- # v0.9.3 (Tue Nov 26 2019)
88
-
89
- #### 🐛 Bug Fix
90
-
91
- - `@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`
92
- - Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie))
93
-
94
- #### Authors: 2
95
-
96
- - Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
97
- - Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))
package/babel.config.js DELETED
@@ -1,38 +0,0 @@
1
- module.exports = (api) => {
2
- api.cache(true);
3
-
4
- return {
5
- presets: [
6
- [
7
- "@babel/env",
8
- {
9
- useBuiltIns: "usage",
10
- },
11
- ],
12
- ],
13
-
14
- plugins: [
15
- "@babel/proposal-class-properties",
16
- "@babel/syntax-object-rest-spread",
17
- process.env.BABEL_ENV !== "module" && "add-module-exports",
18
- [
19
- "transform-inline-environment-variables",
20
- { include: ["BABEL_ENV", "ENV"] },
21
- ],
22
- ].filter(Boolean),
23
-
24
- env: {
25
- test: {
26
- plugins: ["istanbul"],
27
- },
28
- development: {
29
- plugins: [process.env.ENV !== "browser" && "source-map-support"].filter(
30
- Boolean
31
- ),
32
- },
33
- module: {
34
- presets: [["@babel/env", { modules: false }]],
35
- },
36
- },
37
- };
38
- };
package/dist/index.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _utils = require("@jimp/utils");
8
- /**
9
- * Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default
10
- * @param {number} options object
11
- * max: A number auto limited between 0 - 255
12
- * replace: (optional) A number auto limited between 0 - 255 (default 255)
13
- * autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)
14
- * @param {number} cb (optional) a callback for when complete
15
- * @return {this} this for chaining of methods
16
- */
17
- var _default = () => ({
18
- threshold(_ref, cb) {
19
- let {
20
- max,
21
- replace = 255,
22
- autoGreyscale = true
23
- } = _ref;
24
- if (typeof max !== "number") {
25
- return _utils.throwError.call(this, "max must be a number", cb);
26
- }
27
- if (typeof replace !== "number") {
28
- return _utils.throwError.call(this, "replace must be a number", cb);
29
- }
30
- if (typeof autoGreyscale !== "boolean") {
31
- return _utils.throwError.call(this, "autoGreyscale must be a boolean", cb);
32
- }
33
- max = this.constructor.limit255(max);
34
- replace = this.constructor.limit255(replace);
35
- if (autoGreyscale) {
36
- this.greyscale();
37
- }
38
- this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, (x, y, idx) => {
39
- const grey = this.bitmap.data[idx] < max ? this.bitmap.data[idx] : replace;
40
- this.bitmap.data[idx] = grey;
41
- this.bitmap.data[idx + 1] = grey;
42
- this.bitmap.data[idx + 2] = grey;
43
- });
44
- if ((0, _utils.isNodePattern)(cb)) {
45
- cb.call(this, null, this);
46
- }
47
- return this;
48
- }
49
- });
50
- exports.default = _default;
51
- module.exports = exports.default;
52
- module.exports.default = exports.default;
53
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["threshold","cb","max","replace","autoGreyscale","throwError","call","constructor","limit255","greyscale","scanQuiet","bitmap","width","height","x","y","idx","grey","data","isNodePattern"],"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;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AARA,eASe,OAAO;EACpBA,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,OAAOG,iBAAU,CAACC,IAAI,CAAC,IAAI,EAAE,sBAAsB,EAAEL,EAAE,CAAC;IAC1D;IAEA,IAAI,OAAOE,OAAO,KAAK,QAAQ,EAAE;MAC/B,OAAOE,iBAAU,CAACC,IAAI,CAAC,IAAI,EAAE,0BAA0B,EAAEL,EAAE,CAAC;IAC9D;IAEA,IAAI,OAAOG,aAAa,KAAK,SAAS,EAAE;MACtC,OAAOC,iBAAU,CAACC,IAAI,CAAC,IAAI,EAAE,iCAAiC,EAAEL,EAAE,CAAC;IACrE;IAEAC,GAAG,GAAG,IAAI,CAACK,WAAW,CAACC,QAAQ,CAACN,GAAG,CAAC;IACpCC,OAAO,GAAG,IAAI,CAACI,WAAW,CAACC,QAAQ,CAACL,OAAO,CAAC;IAE5C,IAAIC,aAAa,EAAE;MACjB,IAAI,CAACK,SAAS,EAAE;IAClB;IAEA,IAAI,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAACC,MAAM,CAACC,KAAK,EAAE,IAAI,CAACD,MAAM,CAACE,MAAM,EAAE,CAACC,CAAC,EAAEC,CAAC,EAAEC,GAAG,KAAK;MACzE,MAAMC,IAAI,GACR,IAAI,CAACN,MAAM,CAACO,IAAI,CAACF,GAAG,CAAC,GAAGd,GAAG,GAAG,IAAI,CAACS,MAAM,CAACO,IAAI,CAACF,GAAG,CAAC,GAAGb,OAAO;MAE/D,IAAI,CAACQ,MAAM,CAACO,IAAI,CAACF,GAAG,CAAC,GAAGC,IAAI;MAC5B,IAAI,CAACN,MAAM,CAACO,IAAI,CAACF,GAAG,GAAG,CAAC,CAAC,GAAGC,IAAI;MAChC,IAAI,CAACN,MAAM,CAACO,IAAI,CAACF,GAAG,GAAG,CAAC,CAAC,GAAGC,IAAI;IAClC,CAAC,CAAC;IAEF,IAAI,IAAAE,oBAAa,EAAClB,EAAE,CAAC,EAAE;MACrBA,EAAE,CAACK,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC3B;IAEA,OAAO,IAAI;EACb;AACF,CAAC,CAAC;AAAA;AAAA;AAAA"}
package/es/index.js DELETED
@@ -1,45 +0,0 @@
1
- import { isNodePattern, throwError } from "@jimp/utils";
2
-
3
- /**
4
- * Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default
5
- * @param {number} options object
6
- * max: A number auto limited between 0 - 255
7
- * replace: (optional) A number auto limited between 0 - 255 (default 255)
8
- * autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)
9
- * @param {number} cb (optional) a callback for when complete
10
- * @return {this} this for chaining of methods
11
- */
12
- export default (() => ({
13
- threshold(_ref, cb) {
14
- let {
15
- max,
16
- replace = 255,
17
- autoGreyscale = true
18
- } = _ref;
19
- if (typeof max !== "number") {
20
- return throwError.call(this, "max must be a number", cb);
21
- }
22
- if (typeof replace !== "number") {
23
- return throwError.call(this, "replace must be a number", cb);
24
- }
25
- if (typeof autoGreyscale !== "boolean") {
26
- return throwError.call(this, "autoGreyscale must be a boolean", cb);
27
- }
28
- max = this.constructor.limit255(max);
29
- replace = this.constructor.limit255(replace);
30
- if (autoGreyscale) {
31
- this.greyscale();
32
- }
33
- this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, (x, y, idx) => {
34
- const grey = this.bitmap.data[idx] < max ? this.bitmap.data[idx] : replace;
35
- this.bitmap.data[idx] = grey;
36
- this.bitmap.data[idx + 1] = grey;
37
- this.bitmap.data[idx + 2] = grey;
38
- });
39
- if (isNodePattern(cb)) {
40
- cb.call(this, null, this);
41
- }
42
- return this;
43
- }
44
- }));
45
- //# sourceMappingURL=index.js.map
package/es/index.js.map DELETED
@@ -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,IAAI,EAAE,0BAA0B,EAAEJ,EAAE,CAAC;IAC9D;IAEA,IAAI,OAAOG,aAAa,KAAK,SAAS,EAAE;MACtC,OAAOL,UAAU,CAACM,IAAI,CAAC,IAAI,EAAE,iCAAiC,EAAEJ,EAAE,CAAC;IACrE;IAEAC,GAAG,GAAG,IAAI,CAACI,WAAW,CAACC,QAAQ,CAACL,GAAG,CAAC;IACpCC,OAAO,GAAG,IAAI,CAACG,WAAW,CAACC,QAAQ,CAACJ,OAAO,CAAC;IAE5C,IAAIC,aAAa,EAAE;MACjB,IAAI,CAACI,SAAS,EAAE;IAClB;IAEA,IAAI,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAACC,MAAM,CAACC,KAAK,EAAE,IAAI,CAACD,MAAM,CAACE,MAAM,EAAE,CAACC,CAAC,EAAEC,CAAC,EAAEC,GAAG,KAAK;MACzE,MAAMC,IAAI,GACR,IAAI,CAACN,MAAM,CAACO,IAAI,CAACF,GAAG,CAAC,GAAGb,GAAG,GAAG,IAAI,CAACQ,MAAM,CAACO,IAAI,CAACF,GAAG,CAAC,GAAGZ,OAAO;MAE/D,IAAI,CAACO,MAAM,CAACO,IAAI,CAACF,GAAG,CAAC,GAAGC,IAAI;MAC5B,IAAI,CAACN,MAAM,CAACO,IAAI,CAACF,GAAG,GAAG,CAAC,CAAC,GAAGC,IAAI;MAChC,IAAI,CAACN,MAAM,CAACO,IAAI,CAACF,GAAG,GAAG,CAAC,CAAC,GAAGC,IAAI;IAClC,CAAC,CAAC;IAEF,IAAIlB,aAAa,CAACG,EAAE,CAAC,EAAE;MACrBA,EAAE,CAACI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC3B;IAEA,OAAO,IAAI;EACb;AACF,CAAC,CAAC"}
package/index.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { ImageCallback } from "@jimp/core";
2
-
3
- interface Threshold {
4
- threshold(
5
- opts: {
6
- max: number;
7
- replace?: number;
8
- autoGreyscale?: boolean;
9
- },
10
- cb?: ImageCallback<this>
11
- ): this;
12
- }
13
-
14
- export default function (): Threshold;
package/src/index.js DELETED
@@ -1,48 +0,0 @@
1
- import { isNodePattern, throwError } from "@jimp/utils";
2
-
3
- /**
4
- * Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default
5
- * @param {number} options object
6
- * max: A number auto limited between 0 - 255
7
- * replace: (optional) A number auto limited between 0 - 255 (default 255)
8
- * autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)
9
- * @param {number} cb (optional) a callback for when complete
10
- * @return {this} this for chaining of methods
11
- */
12
- export default () => ({
13
- threshold({ max, replace = 255, autoGreyscale = true }, cb) {
14
- if (typeof max !== "number") {
15
- return throwError.call(this, "max must be a number", cb);
16
- }
17
-
18
- if (typeof replace !== "number") {
19
- return throwError.call(this, "replace must be a number", cb);
20
- }
21
-
22
- if (typeof autoGreyscale !== "boolean") {
23
- return throwError.call(this, "autoGreyscale must be a boolean", cb);
24
- }
25
-
26
- max = this.constructor.limit255(max);
27
- replace = this.constructor.limit255(replace);
28
-
29
- if (autoGreyscale) {
30
- this.greyscale();
31
- }
32
-
33
- this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, (x, y, idx) => {
34
- const grey =
35
- this.bitmap.data[idx] < max ? this.bitmap.data[idx] : replace;
36
-
37
- this.bitmap.data[idx] = grey;
38
- this.bitmap.data[idx + 1] = grey;
39
- this.bitmap.data[idx + 2] = grey;
40
- });
41
-
42
- if (isNodePattern(cb)) {
43
- cb.call(this, null, this);
44
- }
45
-
46
- return this;
47
- },
48
- });
Binary file
@@ -1,30 +0,0 @@
1
- import { Jimp, getTestDir } from "@jimp/test-utils";
2
- import configure from "@jimp/custom";
3
- import jpeg from "@jimp/jpeg";
4
- import color from "@jimp/plugin-color";
5
- import resize from "@jimp/plugin-resize";
6
- import expect from "@storybook/expect";
7
-
8
- import threshold from "../src";
9
-
10
- const jimp = configure(
11
- { types: [jpeg], plugins: [threshold, color, resize] },
12
- Jimp
13
- );
14
-
15
- describe("Threshold", function () {
16
- this.timeout(15000);
17
-
18
- it("defines default threshold for lighter backgrounds", async () => {
19
- const expectedImage = await jimp.read(
20
- getTestDir(__dirname) + "/images/hands_mx200_rp255.jpg"
21
- );
22
- const testImage = await jimp.read(
23
- getTestDir(__dirname) + "/images/hands.jpg"
24
- );
25
-
26
- expect(testImage.threshold({ max: 200, replace: 255 }).hash()).toBe(
27
- expectedImage.hash()
28
- );
29
- });
30
- });