@jimp/plugin-threshold 0.22.11 → 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 +5 -0
- package/.tshy/build.json +9 -0
- package/.tshy/commonjs.json +15 -0
- package/.tshy/esm.json +14 -0
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test$colon$browser.log +162 -0
- package/.turbo/turbo-test.log +92 -0
- package/dist/commonjs/index.d.ts +36 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +46 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +7 -0
- package/dist/esm/index.d.ts +36 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +43 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +7 -0
- package/package.json +51 -28
- package/src/index.test.ts +23 -0
- package/src/index.ts +56 -0
- package/tsconfig.json +6 -0
- package/vitest.config.browser.mjs +3 -0
- package/CHANGELOG.md +0 -97
- package/babel.config.js +0 -38
- package/dist/index.js +0 -53
- package/dist/index.js.map +0 -1
- package/es/index.js +0 -45
- package/es/index.js.map +0 -1
- package/index.d.ts +0 -14
- package/src/index.js +0 -48
- package/test/images/hands.jpg +0 -0
- package/test/threshold.test.js +0 -30
- /package/{test/images/hands_mx200_rp255.jpg → src/__image_snapshots__/index-test-ts-src-index-test-ts-threshold-defines-default-threshold-for-lighter-backgrounds-1-snap.png} +0 -0
package/.eslintrc.cjs
ADDED
package/.tshy/build.json
ADDED
package/.tshy/esm.json
ADDED
|
@@ -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
|
+
[7m[1m[36m RUN [39m[22m[27m [36mv1.4.0[39m [90m/Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold[39m
|
|
7
|
+
[2m[32m Browser runner started at http://localhost:5173/[39m[22m
|
|
8
|
+
|
|
9
|
+
[?25l [90m·[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
10
|
+
[90m·[39m Threshold[2m (1)[22m
|
|
11
|
+
[90m·[39m defines default threshold for lighter backgrounds
|
|
12
|
+
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
13
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
14
|
+
[33m⠙[39m defines default threshold for lighter backgrounds
|
|
15
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
16
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
17
|
+
[33m⠹[39m defines default threshold for lighter backgrounds
|
|
18
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
19
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
20
|
+
[33m⠸[39m defines default threshold for lighter backgrounds
|
|
21
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
22
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
23
|
+
[33m⠼[39m defines default threshold for lighter backgrounds
|
|
24
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
25
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
26
|
+
[33m⠴[39m defines default threshold for lighter backgrounds
|
|
27
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
28
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
29
|
+
[33m⠦[39m defines default threshold for lighter backgrounds
|
|
30
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
31
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
32
|
+
[33m⠧[39m defines default threshold for lighter backgrounds
|
|
33
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
34
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
35
|
+
[33m⠇[39m defines default threshold for lighter backgrounds
|
|
36
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
37
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
38
|
+
[33m⠏[39m defines default threshold for lighter backgrounds
|
|
39
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
40
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
41
|
+
[33m⠋[39m defines default threshold for lighter backgrounds
|
|
42
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
43
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
44
|
+
[33m⠙[39m defines default threshold for lighter backgrounds
|
|
45
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
46
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
47
|
+
[33m⠹[39m defines default threshold for lighter backgrounds
|
|
48
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
49
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
50
|
+
[33m⠸[39m defines default threshold for lighter backgrounds
|
|
51
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
52
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
53
|
+
[33m⠼[39m defines default threshold for lighter backgrounds
|
|
54
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
55
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
56
|
+
[33m⠴[39m defines default threshold for lighter backgrounds
|
|
57
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
58
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
59
|
+
[33m⠦[39m defines default threshold for lighter backgrounds
|
|
60
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
61
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
62
|
+
[33m⠧[39m defines default threshold for lighter backgrounds
|
|
63
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
64
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
65
|
+
[33m⠇[39m defines default threshold for lighter backgrounds
|
|
66
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
67
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
68
|
+
[33m⠏[39m defines default threshold for lighter backgrounds
|
|
69
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
70
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
71
|
+
[33m⠋[39m defines default threshold for lighter backgrounds
|
|
72
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
73
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
74
|
+
[33m⠙[39m defines default threshold for lighter backgrounds
|
|
75
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
76
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
77
|
+
[33m⠹[39m defines default threshold for lighter backgrounds
|
|
78
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
79
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
80
|
+
[33m⠸[39m defines default threshold for lighter backgrounds
|
|
81
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
82
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
83
|
+
[33m⠼[39m defines default threshold for lighter backgrounds
|
|
84
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
85
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
86
|
+
[33m⠴[39m defines default threshold for lighter backgrounds
|
|
87
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
88
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
89
|
+
[33m⠦[39m defines default threshold for lighter backgrounds
|
|
90
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
91
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
92
|
+
[33m⠧[39m defines default threshold for lighter backgrounds
|
|
93
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [90m·[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
94
|
+
[90m·[39m Threshold[2m (1)[22m
|
|
95
|
+
[90m·[39m defines default threshold for lighter backgrounds
|
|
96
|
+
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
97
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
98
|
+
[33m⠙[39m defines default threshold for lighter backgrounds
|
|
99
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
100
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
101
|
+
[33m⠹[39m defines default threshold for lighter backgrounds
|
|
102
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
103
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
104
|
+
[33m⠸[39m defines default threshold for lighter backgrounds
|
|
105
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
106
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
107
|
+
[33m⠼[39m defines default threshold for lighter backgrounds
|
|
108
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
109
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
110
|
+
[33m⠴[39m defines default threshold for lighter backgrounds
|
|
111
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
112
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
113
|
+
[33m⠦[39m defines default threshold for lighter backgrounds
|
|
114
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
115
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
116
|
+
[33m⠧[39m defines default threshold for lighter backgrounds
|
|
117
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
118
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
119
|
+
[33m⠇[39m defines default threshold for lighter backgrounds
|
|
120
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
121
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
122
|
+
[33m⠏[39m defines default threshold for lighter backgrounds
|
|
123
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
124
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
125
|
+
[33m⠋[39m defines default threshold for lighter backgrounds
|
|
126
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
127
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
128
|
+
[33m⠙[39m defines default threshold for lighter backgrounds
|
|
129
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
130
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
131
|
+
[33m⠹[39m defines default threshold for lighter backgrounds
|
|
132
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
133
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
134
|
+
[33m⠸[39m defines default threshold for lighter backgrounds
|
|
135
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
136
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
137
|
+
[33m⠼[39m defines default threshold for lighter backgrounds
|
|
138
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
139
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
140
|
+
[33m⠴[39m defines default threshold for lighter backgrounds
|
|
141
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
142
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
143
|
+
[33m⠦[39m defines default threshold for lighter backgrounds
|
|
144
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
145
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
146
|
+
[33m⠧[39m defines default threshold for lighter backgrounds
|
|
147
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
148
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
149
|
+
[33m⠇[39m defines default threshold for lighter backgrounds
|
|
150
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m[33m 433[2mms[22m[39m
|
|
151
|
+
[32m✓[39m Threshold[2m (1)[22m[33m 433[2mms[22m[39m
|
|
152
|
+
[32m✓[39m defines default threshold for lighter backgrounds[33m 432[2mms[22m[39m
|
|
153
|
+
[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m[33m 433[2mms[22m[39m
|
|
154
|
+
[32m✓[39m Threshold[2m (1)[22m[33m 433[2mms[22m[39m
|
|
155
|
+
[32m✓[39m defines default threshold for lighter backgrounds[33m 432[2mms[22m[39m
|
|
156
|
+
|
|
157
|
+
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
158
|
+
[2m Tests [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
159
|
+
[2m Start at [22m 14:34:41
|
|
160
|
+
[2m Duration [22m 1.80s[2m (transform 0ms, setup 1ms, collect 51ms, tests 433ms, environment 0ms, prepare 0ms)[22m
|
|
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
|
+
[7m[1m[36m RUN [39m[22m[27m [36mv1.4.0[39m [90m/Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold[39m
|
|
7
|
+
|
|
8
|
+
[?25l [90m·[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
9
|
+
[90m·[39m Threshold[2m (1)[22m
|
|
10
|
+
[90m·[39m defines default threshold for lighter backgrounds
|
|
11
|
+
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
12
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
13
|
+
[33m⠙[39m defines default threshold for lighter backgrounds
|
|
14
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
15
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
16
|
+
[33m⠹[39m defines default threshold for lighter backgrounds
|
|
17
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
18
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
19
|
+
[33m⠸[39m defines default threshold for lighter backgrounds
|
|
20
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
21
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
22
|
+
[33m⠼[39m defines default threshold for lighter backgrounds
|
|
23
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
24
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
25
|
+
[33m⠴[39m defines default threshold for lighter backgrounds
|
|
26
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
27
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
28
|
+
[33m⠦[39m defines default threshold for lighter backgrounds
|
|
29
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
30
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
31
|
+
[33m⠧[39m defines default threshold for lighter backgrounds
|
|
32
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
33
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
34
|
+
[33m⠇[39m defines default threshold for lighter backgrounds
|
|
35
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
36
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
37
|
+
[33m⠏[39m defines default threshold for lighter backgrounds
|
|
38
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
39
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
40
|
+
[33m⠋[39m defines default threshold for lighter backgrounds
|
|
41
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
42
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
43
|
+
[33m⠙[39m defines default threshold for lighter backgrounds
|
|
44
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
45
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
46
|
+
[33m⠹[39m defines default threshold for lighter backgrounds
|
|
47
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
48
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
49
|
+
[33m⠸[39m defines default threshold for lighter backgrounds
|
|
50
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
51
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
52
|
+
[33m⠼[39m defines default threshold for lighter backgrounds
|
|
53
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
54
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
55
|
+
[33m⠴[39m defines default threshold for lighter backgrounds
|
|
56
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
57
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
58
|
+
[33m⠦[39m defines default threshold for lighter backgrounds
|
|
59
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
60
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
61
|
+
[33m⠧[39m defines default threshold for lighter backgrounds
|
|
62
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
63
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
64
|
+
[33m⠇[39m defines default threshold for lighter backgrounds
|
|
65
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
66
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
67
|
+
[33m⠏[39m defines default threshold for lighter backgrounds
|
|
68
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
69
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
70
|
+
[33m⠋[39m defines default threshold for lighter backgrounds
|
|
71
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
72
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
73
|
+
[33m⠙[39m defines default threshold for lighter backgrounds
|
|
74
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
75
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
76
|
+
[33m⠹[39m defines default threshold for lighter backgrounds
|
|
77
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m
|
|
78
|
+
[33m❯[39m Threshold[2m (1)[22m
|
|
79
|
+
[33m⠸[39m defines default threshold for lighter backgrounds
|
|
80
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m[33m 550[2mms[22m[39m
|
|
81
|
+
[32m✓[39m Threshold[2m (1)[22m[33m 548[2mms[22m[39m
|
|
82
|
+
[32m✓[39m defines default threshold for lighter backgrounds[33m 548[2mms[22m[39m
|
|
83
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (1)[22m[33m 550[2mms[22m[39m
|
|
84
|
+
[32m✓[39m Threshold[2m (1)[22m[33m 548[2mms[22m[39m
|
|
85
|
+
[32m✓[39m defines default threshold for lighter backgrounds[33m 548[2mms[22m[39m
|
|
86
|
+
|
|
87
|
+
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
88
|
+
[2m Tests [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
89
|
+
[2m Start at [22m 14:26:15
|
|
90
|
+
[2m Duration [22m 888ms[2m (transform 124ms, setup 0ms, collect 149ms, tests 550ms, environment 0ms, prepare 50ms)[22m
|
|
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,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"}
|
package/package.json
CHANGED
|
@@ -1,42 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jimp/plugin-threshold",
|
|
3
|
-
"version": "0.
|
|
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
|
-
"
|
|
11
|
-
"test
|
|
12
|
-
"test:
|
|
13
|
-
"build": "
|
|
14
|
-
"
|
|
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/
|
|
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
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
"tshy": {
|
|
36
|
+
"exclude": [
|
|
37
|
+
"**/*.test.ts"
|
|
38
|
+
],
|
|
39
|
+
"exports": {
|
|
40
|
+
"./package.json": "./package.json",
|
|
41
|
+
".": "./src/index.ts"
|
|
42
|
+
}
|
|
30
43
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
"
|
|
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
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
|
-

|
|
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
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
|
-
});
|
package/test/images/hands.jpg
DELETED
|
Binary file
|
package/test/threshold.test.js
DELETED
|
@@ -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
|
-
});
|