Initial commit

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

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"module": "nodenext",
"moduleResolution": "nodenext"
}
}
+17
View File
@@ -0,0 +1,17 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.cts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../**/*.test.ts",
"../src/**/*.mts",
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/commonjs"
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.mts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../**/*.test.ts",
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/esm"
}
}
+5
View File
@@ -0,0 +1,5 @@

> @jimp/plugin-threshold@1.5.0 build /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
> tshy
+5
View File
@@ -0,0 +1,5 @@

> @jimp/plugin-threshold@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
> eslint .
+147
View File
@@ -0,0 +1,147 @@
> @jimp/plugin-threshold@1.1.1 test:browser /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
> vitest --config vitest.config.browser.mjs "--watch=false" "--u"
 RUN  v1.4.0 /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
 Browser runner started at http://localhost:5173/
[?25l · src/index.test.ts (1)
· Threshold (1)
· defines default threshold for lighter backgrounds
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠙ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠹ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠸ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠼ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠴ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠦ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠧ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠇ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠏ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠋ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠙ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠹ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠸ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠼ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠴ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠦ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠧ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠇ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠏ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠋ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠙ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠹ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠸ defines default threshold for lighter backgrounds
[?25l · src/index.test.ts (1)
· Threshold (1)
· defines default threshold for lighter backgrounds
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠙ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠹ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠸ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠼ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠴ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠦ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠧ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠇ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠏ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠋ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠙ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠹ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠸ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠼ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠴ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠦ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠧ defines default threshold for lighter backgrounds
[?25l ✓ src/index.test.ts (1) 420ms
✓ Threshold (1) 420ms
✓ defines default threshold for lighter backgrounds 420ms
 ✓ src/index.test.ts (1) 420ms
✓ Threshold (1) 420ms
✓ defines default threshold for lighter backgrounds 420ms
 Test Files  1 passed (1)
 Tests  1 passed (1)
 Start at  00:42:21
 Duration  1.81s (transform 0ms, setup 0ms, collect 59ms, tests 420ms, environment 0ms, prepare 0ms)
[?25h[?25h
+108
View File
@@ -0,0 +1,108 @@

> @jimp/plugin-threshold@1.1.2 test /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
> vitest "--watch=false" "-u"
 RUN  v2.0.5 /Users/andrewlisowski/Documents/jimp/plugins/plugin-threshold
[?25l · src/index.test.ts (1)
· Threshold (1)
· defines default threshold for lighter backgrounds
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠙ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠹ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠸ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠼ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠴ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠦ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠧ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠇ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠏ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠋ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠙ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠹ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠸ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠼ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠴ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠦ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠧ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠇ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠏ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠋ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠙ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠹ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠸ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠼ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠴ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠦ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠧ defines default threshold for lighter backgrounds
[?25l ❯ src/index.test.ts (1)
❯ Threshold (1)
⠇ defines default threshold for lighter backgrounds
[?25l ✓ src/index.test.ts (1) 651ms
✓ Threshold (1) 651ms
✓ defines default threshold for lighter backgrounds 650ms
 ✓ src/index.test.ts (1) 651ms
✓ Threshold (1) 651ms
✓ defines default threshold for lighter backgrounds 650ms
 Test Files  1 passed (1)
 Tests  1 passed (1)
 Start at  01:23:31
 Duration  1.36s (transform 157ms, setup 0ms, collect 243ms, tests 651ms, environment 0ms, prepare 88ms)
[?25h[?25h
+52
View File
@@ -0,0 +1,52 @@
# v1.1.3 (Mon Sep 02 2024)
#### 🐛 Bug Fix
- Update deps [#1319](https://github.com/jimp-dev/jimp/pull/1319) ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
---
# v1.1.0 (Sun Sep 01 2024)
#### ⚠️ Pushed to `main`
- upgrade tshy ([@hipstersmoothie](https://github.com/hipstersmoothie))
- update more docs ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
---
# v1.0.3 (Sat Aug 31 2024)
#### 🐛 Bug Fix
- Fix build [#1303](https://github.com/jimp-dev/jimp/pull/1303) ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### ⚠️ Pushed to `main`
- add clean script ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
---
# v1.0.2 (Sat Aug 31 2024)
#### ⚠️ Pushed to `main`
- set side effects ([@hipstersmoothie](https://github.com/hipstersmoothie))
- fix versions ([@hipstersmoothie](https://github.com/hipstersmoothie))
- add publish config ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Oliver Moran
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+10
View File
@@ -0,0 +1,10 @@
<div align="center">
<img width="200" height="200"
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
<h1>@jimp/plugin-threshold</h1>
<p>Lightens an image.</p>
</div>
This is useful as a simplified method for processing scanned drawings, signatures, etc
- [threshold](http://jimp-dev.github.io/jimp/api/jimp/classes/jimp#threshold)
+36
View File
@@ -0,0 +1,36 @@
import { JimpClass } from "@jimp/types";
import { z } from "zod";
declare const ThresholdOptionsSchema: z.ZodObject<{
/** A number auto limited between 0 - 255 */
max: z.ZodNumber;
/** A number auto limited between 0 - 255 (default 255) */
replace: z.ZodOptional<z.ZodNumber>;
/** A boolean whether to apply greyscale beforehand (default true) */
autoGreyscale: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
max: number;
replace?: number | undefined;
autoGreyscale?: boolean | undefined;
}, {
max: number;
replace?: number | undefined;
autoGreyscale?: boolean | undefined;
}>;
export type ThresholdOptions = z.infer<typeof ThresholdOptionsSchema>;
export declare const methods: {
/**
* Applies a minimum color threshold to a grayscale image.
* Converts image to grayscale by default.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.threshold({ max: 150 });
* ```
*/
threshold<I extends JimpClass>(image: I, options: ThresholdOptions): I;
};
export {};
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,sBAAsB;IAC1B,4CAA4C;;IAE5C,2DAA2D;;IAE3D,sEAAsE;;;;;;;;;;EAEtE,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;OAWG;cACO,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,gBAAgB;CA0BnE,CAAC"}
+46
View File
@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.methods = void 0;
const utils_1 = require("@jimp/utils");
const plugin_color_1 = require("@jimp/plugin-color");
const zod_1 = require("zod");
const ThresholdOptionsSchema = zod_1.z.object({
/** A number auto limited between 0 - 255 */
max: zod_1.z.number().min(0).max(255),
/** A number auto limited between 0 - 255 (default 255) */
replace: zod_1.z.number().min(0).max(255).optional(),
/** A boolean whether to apply greyscale beforehand (default true) */
autoGreyscale: zod_1.z.boolean().optional(),
});
exports.methods = {
/**
* Applies a minimum color threshold to a grayscale image.
* Converts image to grayscale by default.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.threshold({ max: 150 });
* ```
*/
threshold(image, options) {
let { max, replace = 255,
// eslint-disable-next-line prefer-const
autoGreyscale = true, } = ThresholdOptionsSchema.parse(options);
max = (0, utils_1.limit255)(max);
replace = (0, utils_1.limit255)(replace);
if (autoGreyscale) {
plugin_color_1.methods.greyscale(image);
}
image.scan((_, __, idx) => {
const grey = image.bitmap.data[idx] < max ? image.bitmap.data[idx] : replace;
image.bitmap.data[idx] = grey;
image.bitmap.data[idx + 1] = grey;
image.bitmap.data[idx + 2] = grey;
});
return image;
},
};
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,uCAAuC;AACvC,qDAAsD;AACtD,6BAAwB;AAEx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G,IAAI,CAAC;YAClC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+36
View File
@@ -0,0 +1,36 @@
import { JimpClass } from "@jimp/types";
import { z } from "zod";
declare const ThresholdOptionsSchema: z.ZodObject<{
/** A number auto limited between 0 - 255 */
max: z.ZodNumber;
/** A number auto limited between 0 - 255 (default 255) */
replace: z.ZodOptional<z.ZodNumber>;
/** A boolean whether to apply greyscale beforehand (default true) */
autoGreyscale: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
max: number;
replace?: number | undefined;
autoGreyscale?: boolean | undefined;
}, {
max: number;
replace?: number | undefined;
autoGreyscale?: boolean | undefined;
}>;
export type ThresholdOptions = z.infer<typeof ThresholdOptionsSchema>;
export declare const methods: {
/**
* Applies a minimum color threshold to a grayscale image.
* Converts image to grayscale by default.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.threshold({ max: 150 });
* ```
*/
threshold<I extends JimpClass>(image: I, options: ThresholdOptions): I;
};
export {};
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,sBAAsB;IAC1B,4CAA4C;;IAE5C,2DAA2D;;IAE3D,sEAAsE;;;;;;;;;;EAEtE,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;OAWG;cACO,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,gBAAgB;CA0BnE,CAAC"}
+43
View File
@@ -0,0 +1,43 @@
import { limit255 } from "@jimp/utils";
import { methods as color } from "@jimp/plugin-color";
import { z } from "zod";
const ThresholdOptionsSchema = z.object({
/** A number auto limited between 0 - 255 */
max: z.number().min(0).max(255),
/** A number auto limited between 0 - 255 (default 255) */
replace: z.number().min(0).max(255).optional(),
/** A boolean whether to apply greyscale beforehand (default true) */
autoGreyscale: z.boolean().optional(),
});
export const methods = {
/**
* Applies a minimum color threshold to a grayscale image.
* Converts image to grayscale by default.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.threshold({ max: 150 });
* ```
*/
threshold(image, options) {
let { max, replace = 255,
// eslint-disable-next-line prefer-const
autoGreyscale = true, } = ThresholdOptionsSchema.parse(options);
max = limit255(max);
replace = limit255(replace);
if (autoGreyscale) {
color.greyscale(image);
}
image.scan((_, __, idx) => {
const grey = image.bitmap.data[idx] < max ? image.bitmap.data[idx] : replace;
image.bitmap.data[idx] = grey;
image.bitmap.data[idx + 1] = grey;
image.bitmap.data[idx + 2] = grey;
});
return image;
},
};
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,4CAA4C;IAC5C,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAC/B,2DAA2D;IAC3D,OAAO,EAAE,CAAC,CAAC,MAAM,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-0,0 +1,2 @@
import shared from "@jimp/config-eslint/base.js";
export default [...shared];
+70
View File
@@ -0,0 +1,70 @@
{
"name": "@jimp/plugin-threshold",
"version": "1.6.0",
"repository": "jimp-dev/jimp",
"engines": {
"node": ">=18"
},
"scripts": {
"lint": "eslint .",
"test": "vitest",
"test:browser": "vitest --config vitest.config.browser.mjs",
"build": "tshy",
"dev": "tshy --watch",
"clean": "rm -rf node_modules .tshy .tshy-build dist .turbo"
},
"author": "Andrew Lisowski <lisowski54@gmail.com>",
"license": "MIT",
"devDependencies": {
"@jimp/config-eslint": "1.6.0",
"@jimp/config-typescript": "1.6.0",
"@jimp/config-vitest": "1.6.0",
"@jimp/js-jpeg": "1.6.0",
"@jimp/test-utils": "1.6.0",
"@vitest/browser": "^2.0.5",
"eslint": "^9.9.1",
"tshy": "^3.0.2",
"typescript": "^5.5.4",
"vite-plugin-node-polyfills": "^0.22.0",
"vitest": "^2.0.5"
},
"dependencies": {
"@jimp/core": "1.6.0",
"@jimp/plugin-color": "1.6.0",
"@jimp/plugin-hash": "1.6.0",
"@jimp/types": "1.6.0",
"@jimp/utils": "1.6.0",
"zod": "^3.23.8"
},
"tshy": {
"exclude": [
"**/*.test.ts"
],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"type": "module",
"publishConfig": {
"access": "public"
},
"sideEffects": false,
"module": "./dist/esm/index.js",
"gitHead": "c88abe6046dccbdb6e4f5f00c3dd403c81d83515"
}
+23
View File
@@ -0,0 +1,23 @@
import { expect, test, describe } from "vitest";
import "@jimp/test-utils";
import jpeg from "@jimp/js-jpeg";
import { methods as hash } from "@jimp/plugin-hash";
import { createJimp } from "@jimp/core";
import { methods as threshold } from "./index.js";
import { getTestImagePath } from "@jimp/test-utils";
const jimp = createJimp({ formats: [jpeg], plugins: [threshold, hash] });
describe("Threshold", () => {
test("defines default threshold for lighter backgrounds", async () => {
const testImage = await jimp.read(getTestImagePath("hands.jpg"));
const expectedImage = await jimp.read(
getTestImagePath("hands_mx200_rp255.jpg"),
);
const output = testImage.threshold({ max: 200, replace: 255 }).hash();
expect(output).toStrictEqual(expectedImage.hash());
});
});
+56
View File
@@ -0,0 +1,56 @@
import { JimpClass } from "@jimp/types";
import { limit255 } from "@jimp/utils";
import { methods as color } from "@jimp/plugin-color";
import { z } from "zod";
const ThresholdOptionsSchema = z.object({
/** A number auto limited between 0 - 255 */
max: z.number().min(0).max(255),
/** A number auto limited between 0 - 255 (default 255) */
replace: z.number().min(0).max(255).optional(),
/** A boolean whether to apply greyscale beforehand (default true) */
autoGreyscale: z.boolean().optional(),
});
export type ThresholdOptions = z.infer<typeof ThresholdOptionsSchema>;
export const methods = {
/**
* Applies a minimum color threshold to a grayscale image.
* Converts image to grayscale by default.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.threshold({ max: 150 });
* ```
*/
threshold<I extends JimpClass>(image: I, options: ThresholdOptions) {
let {
max,
replace = 255,
// eslint-disable-next-line prefer-const
autoGreyscale = true,
} = ThresholdOptionsSchema.parse(options);
max = limit255(max);
replace = limit255(replace);
if (autoGreyscale) {
color.greyscale(image);
}
image.scan((_, __, idx) => {
const grey =
image.bitmap.data[idx]! < max ? image.bitmap.data[idx]! : replace;
image.bitmap.data[idx] = grey;
image.bitmap.data[idx + 1] = grey;
image.bitmap.data[idx + 2] = grey;
});
return image;
},
};
+6
View File
@@ -0,0 +1,6 @@
{
"extends": "@jimp/config-typescript/base.json",
"compilerOptions": {
"outDir": "dist"
}
}
+3
View File
@@ -0,0 +1,3 @@
import config from "@jimp/config-vitest/browser";
export default config;