@depup/jimp__plugin-mask 1.6.1-depup.30
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/.tshy/build.json +8 -0
- package/.tshy/commonjs.json +17 -0
- package/.tshy/esm.json +16 -0
- package/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +52 -0
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/changes.json +10 -0
- package/dist/commonjs/index.d.ts +102 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +63 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/esm/index.d.ts +102 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +60 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/eslint.config.mjs +2 -0
- package/package.json +85 -0
- package/src/__snapshots__/index.test.ts.snap +125 -0
- package/src/index.test.ts +95 -0
- package/src/index.ts +71 -0
- package/tsconfig.json +6 -0
- package/vitest.config.browser.mjs +3 -0
package/.tshy/build.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./build.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"../src/**/*.ts",
|
|
5
|
+
"../src/**/*.cts",
|
|
6
|
+
"../src/**/*.tsx",
|
|
7
|
+
"../src/**/*.json"
|
|
8
|
+
],
|
|
9
|
+
"exclude": [
|
|
10
|
+
"../**/*.test.ts",
|
|
11
|
+
"../src/**/*.mts",
|
|
12
|
+
"../src/package.json"
|
|
13
|
+
],
|
|
14
|
+
"compilerOptions": {
|
|
15
|
+
"outDir": "../.tshy-build/commonjs"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/.tshy/esm.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./build.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"../src/**/*.ts",
|
|
5
|
+
"../src/**/*.mts",
|
|
6
|
+
"../src/**/*.tsx",
|
|
7
|
+
"../src/**/*.json"
|
|
8
|
+
],
|
|
9
|
+
"exclude": [
|
|
10
|
+
"../**/*.test.ts",
|
|
11
|
+
"../src/package.json"
|
|
12
|
+
],
|
|
13
|
+
"compilerOptions": {
|
|
14
|
+
"outDir": "../.tshy-build/esm"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# v1.1.3 (Mon Sep 02 2024)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- Update deps [#1319](https://github.com/jimp-dev/jimp/pull/1319) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# v1.1.0 (Sun Sep 01 2024)
|
|
14
|
+
|
|
15
|
+
#### ⚠️ Pushed to `main`
|
|
16
|
+
|
|
17
|
+
- upgrade tshy ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
18
|
+
- update more docs ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
19
|
+
|
|
20
|
+
#### Authors: 1
|
|
21
|
+
|
|
22
|
+
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
# v1.0.3 (Sat Aug 31 2024)
|
|
27
|
+
|
|
28
|
+
#### 🐛 Bug Fix
|
|
29
|
+
|
|
30
|
+
- Fix build [#1303](https://github.com/jimp-dev/jimp/pull/1303) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
31
|
+
|
|
32
|
+
#### ⚠️ Pushed to `main`
|
|
33
|
+
|
|
34
|
+
- add clean script ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
35
|
+
|
|
36
|
+
#### Authors: 1
|
|
37
|
+
|
|
38
|
+
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
# v1.0.2 (Sat Aug 31 2024)
|
|
43
|
+
|
|
44
|
+
#### ⚠️ Pushed to `main`
|
|
45
|
+
|
|
46
|
+
- set side effects ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
47
|
+
- fix versions ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
48
|
+
- add publish config ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
49
|
+
|
|
50
|
+
#### Authors: 1
|
|
51
|
+
|
|
52
|
+
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Oliver Moran
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @depup/jimp__plugin-mask
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [@jimp/plugin-mask](https://www.npmjs.com/package/@jimp/plugin-mask)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/jimp__plugin-mask
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [@jimp/plugin-mask](https://www.npmjs.com/package/@jimp/plugin-mask) @ 1.6.1 |
|
|
17
|
+
| Processed | 2026-07-21 |
|
|
18
|
+
| Smoke test | failed |
|
|
19
|
+
| Deps updated | 1 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| zod | ^3.23.8 | ^4.4.3 |
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/@jimp/plugin-mask
|
|
30
|
+
|
|
31
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { JimpClass } from "@jimp/types";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
declare const MaskOptionsSchema: z.ZodUnion<[z.ZodObject<{
|
|
4
|
+
bitmap: z.ZodObject<{
|
|
5
|
+
data: z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
|
|
6
|
+
width: z.ZodNumber;
|
|
7
|
+
height: z.ZodNumber;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
data: Buffer | Uint8Array;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}, {
|
|
13
|
+
data: Buffer | Uint8Array;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
}>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
bitmap: {
|
|
19
|
+
data: Buffer | Uint8Array;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
}, {
|
|
24
|
+
bitmap: {
|
|
25
|
+
data: Buffer | Uint8Array;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
29
|
+
}>, z.ZodObject<{
|
|
30
|
+
src: z.ZodObject<{
|
|
31
|
+
bitmap: z.ZodObject<{
|
|
32
|
+
data: z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
|
|
33
|
+
width: z.ZodNumber;
|
|
34
|
+
height: z.ZodNumber;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
data: Buffer | Uint8Array;
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
}, {
|
|
40
|
+
data: Buffer | Uint8Array;
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
}>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
bitmap: {
|
|
46
|
+
data: Buffer | Uint8Array;
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
};
|
|
50
|
+
}, {
|
|
51
|
+
bitmap: {
|
|
52
|
+
data: Buffer | Uint8Array;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
/** the x position to draw the image */
|
|
58
|
+
x: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
/** the y position to draw the image */
|
|
60
|
+
y: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
src: {
|
|
63
|
+
bitmap: {
|
|
64
|
+
data: Buffer | Uint8Array;
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
x?: number | undefined;
|
|
70
|
+
y?: number | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
src: {
|
|
73
|
+
bitmap: {
|
|
74
|
+
data: Buffer | Uint8Array;
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
x?: number | undefined;
|
|
80
|
+
y?: number | undefined;
|
|
81
|
+
}>]>;
|
|
82
|
+
export type MaskOptions = z.infer<typeof MaskOptionsSchema>;
|
|
83
|
+
export declare const methods: {
|
|
84
|
+
/**
|
|
85
|
+
* Masks a source image on to this image using average pixel colour. A completely black pixel on the mask will turn a pixel in the image completely transparent.
|
|
86
|
+
* @param src the source Jimp instance
|
|
87
|
+
* @param x the horizontal position to blit the image
|
|
88
|
+
* @param y the vertical position to blit the image
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { Jimp } from "jimp";
|
|
92
|
+
*
|
|
93
|
+
* const image = await Jimp.read("test/image.png");
|
|
94
|
+
* const mask = await Jimp.read("test/mask.png");
|
|
95
|
+
*
|
|
96
|
+
* image.mask(mask);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
mask<I extends JimpClass>(image: I, options: MaskOptions): I;
|
|
100
|
+
};
|
|
101
|
+
export {};
|
|
102
|
+
//# 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,EAAmB,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,QAAA,MAAM,iBAAiB;;oCAcZ,MAAK,gBAAe,MAAO;;;;cAMO,MAAO;;;;cAIzC,MAAO;;;;;;cAOd,MAAK;;;;;;cAGc,MACpB;;;;;;;wCArBQ,MAAK,gBAAe,MAAO;;;;kBAMO,MAAO;;;;kBAIzC,MAAO;;;;;;kBAOd,MAAK;;;;;;kBAGc,MACpB;;;;;IAzCD,uCAAuC;;IAEvC,uCAAuC;;;;;kBAmCrC,MAAK;;;;;;;;;;kBAGc,MACpB;;;;;;;IAnC0E,CAAC;AAE9E,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;;;OAcG;SACE,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,WAAW;CAuCzD,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.methods = void 0;
|
|
4
|
+
const types_1 = require("@jimp/types");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const MaskOptionsObjectSchema = zod_1.z.object({
|
|
7
|
+
src: types_1.JimpClassSchema,
|
|
8
|
+
/** the x position to draw the image */
|
|
9
|
+
x: zod_1.z.number().optional(),
|
|
10
|
+
/** the y position to draw the image */
|
|
11
|
+
y: zod_1.z.number().optional(),
|
|
12
|
+
});
|
|
13
|
+
const MaskOptionsSchema = zod_1.z.union([types_1.JimpClassSchema, MaskOptionsObjectSchema]);
|
|
14
|
+
exports.methods = {
|
|
15
|
+
/**
|
|
16
|
+
* Masks a source image on to this image using average pixel colour. A completely black pixel on the mask will turn a pixel in the image completely transparent.
|
|
17
|
+
* @param src the source Jimp instance
|
|
18
|
+
* @param x the horizontal position to blit the image
|
|
19
|
+
* @param y the vertical position to blit the image
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { Jimp } from "jimp";
|
|
23
|
+
*
|
|
24
|
+
* const image = await Jimp.read("test/image.png");
|
|
25
|
+
* const mask = await Jimp.read("test/mask.png");
|
|
26
|
+
*
|
|
27
|
+
* image.mask(mask);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
mask(image, options) {
|
|
31
|
+
MaskOptionsSchema.parse(options);
|
|
32
|
+
let src;
|
|
33
|
+
let x;
|
|
34
|
+
let y;
|
|
35
|
+
if ("bitmap" in options) {
|
|
36
|
+
src = options;
|
|
37
|
+
x = 0;
|
|
38
|
+
y = 0;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
src = options.src;
|
|
42
|
+
x = options.x ?? 0;
|
|
43
|
+
y = options.y ?? 0;
|
|
44
|
+
}
|
|
45
|
+
// round input
|
|
46
|
+
x = Math.round(x);
|
|
47
|
+
y = Math.round(y);
|
|
48
|
+
const w = image.bitmap.width;
|
|
49
|
+
const h = image.bitmap.height;
|
|
50
|
+
src.scan(function (sx, sy, idx) {
|
|
51
|
+
const destX = x + sx;
|
|
52
|
+
const destY = y + sy;
|
|
53
|
+
if (destX >= 0 && destY >= 0 && destX < w && destY < h) {
|
|
54
|
+
const dstIdx = image.getPixelIndex(destX, destY);
|
|
55
|
+
const { data } = src.bitmap;
|
|
56
|
+
const avg = (data[idx + 0] + data[idx + 1] + data[idx + 2]) / 3;
|
|
57
|
+
image.bitmap.data[dstIdx + 3] *= avg / 255;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return image;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAyD;AACzD,6BAAwB;AAExB,MAAM,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IACvC,GAAG,EAAE,uBAAe;IACpB,uCAAuC;IACvC,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxB,uCAAuC;IACvC,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,OAAC,CAAC,KAAK,CAAC,CAAC,uBAAe,EAAE,uBAAuB,CAAC,CAAC,CAAC;AAIjE,QAAA,OAAO,GAAG;IACrB;;;;;;;;;;;;;;OAcG;IACH,IAAI,CAAsB,KAAQ,EAAE,OAAoB;QACtD,iBAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEjC,IAAI,GAAc,CAAC;QACnB,IAAI,CAAS,CAAC;QACd,IAAI,CAAS,CAAC;QAEd,IAAI,QAAQ,IAAI,OAAO,EAAE,CAAC;YACxB,GAAG,GAAG,OAA+B,CAAC;YACtC,CAAC,GAAG,CAAC,CAAC;YACN,CAAC,GAAG,CAAC,CAAC;QACR,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,OAAO,CAAC,GAA2B,CAAC;YAC1C,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QAED,cAAc;QACd,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAElB,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;QAC7B,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;QAE9B,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,GAAG;YAC5B,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC;YAErB,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;gBACvD,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBACjD,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;gBAC5B,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,CAAC,GAAG,CAAC,CAAC;gBAEnE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,GAAG,GAAG,GAAG,CAAC;YAC7C,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { JimpClass } from "@jimp/types";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
declare const MaskOptionsSchema: z.ZodUnion<[z.ZodObject<{
|
|
4
|
+
bitmap: z.ZodObject<{
|
|
5
|
+
data: z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
|
|
6
|
+
width: z.ZodNumber;
|
|
7
|
+
height: z.ZodNumber;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
data: Buffer | Uint8Array;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}, {
|
|
13
|
+
data: Buffer | Uint8Array;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
}>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
bitmap: {
|
|
19
|
+
data: Buffer | Uint8Array;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
}, {
|
|
24
|
+
bitmap: {
|
|
25
|
+
data: Buffer | Uint8Array;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
29
|
+
}>, z.ZodObject<{
|
|
30
|
+
src: z.ZodObject<{
|
|
31
|
+
bitmap: z.ZodObject<{
|
|
32
|
+
data: z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
|
|
33
|
+
width: z.ZodNumber;
|
|
34
|
+
height: z.ZodNumber;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
data: Buffer | Uint8Array;
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
}, {
|
|
40
|
+
data: Buffer | Uint8Array;
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
}>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
bitmap: {
|
|
46
|
+
data: Buffer | Uint8Array;
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
};
|
|
50
|
+
}, {
|
|
51
|
+
bitmap: {
|
|
52
|
+
data: Buffer | Uint8Array;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
/** the x position to draw the image */
|
|
58
|
+
x: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
/** the y position to draw the image */
|
|
60
|
+
y: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
src: {
|
|
63
|
+
bitmap: {
|
|
64
|
+
data: Buffer | Uint8Array;
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
x?: number | undefined;
|
|
70
|
+
y?: number | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
src: {
|
|
73
|
+
bitmap: {
|
|
74
|
+
data: Buffer | Uint8Array;
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
x?: number | undefined;
|
|
80
|
+
y?: number | undefined;
|
|
81
|
+
}>]>;
|
|
82
|
+
export type MaskOptions = z.infer<typeof MaskOptionsSchema>;
|
|
83
|
+
export declare const methods: {
|
|
84
|
+
/**
|
|
85
|
+
* Masks a source image on to this image using average pixel colour. A completely black pixel on the mask will turn a pixel in the image completely transparent.
|
|
86
|
+
* @param src the source Jimp instance
|
|
87
|
+
* @param x the horizontal position to blit the image
|
|
88
|
+
* @param y the vertical position to blit the image
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { Jimp } from "jimp";
|
|
92
|
+
*
|
|
93
|
+
* const image = await Jimp.read("test/image.png");
|
|
94
|
+
* const mask = await Jimp.read("test/mask.png");
|
|
95
|
+
*
|
|
96
|
+
* image.mask(mask);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
mask<I extends JimpClass>(image: I, options: MaskOptions): I;
|
|
100
|
+
};
|
|
101
|
+
export {};
|
|
102
|
+
//# 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,EAAmB,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,QAAA,MAAM,iBAAiB;;oCAcZ,MAAK,gBAAe,MAAO;;;;cAMO,MAAO;;;;cAIzC,MAAO;;;;;;cAOd,MAAK;;;;;;cAGc,MACpB;;;;;;;wCArBQ,MAAK,gBAAe,MAAO;;;;kBAMO,MAAO;;;;kBAIzC,MAAO;;;;;;kBAOd,MAAK;;;;;;kBAGc,MACpB;;;;;IAzCD,uCAAuC;;IAEvC,uCAAuC;;;;;kBAmCrC,MAAK;;;;;;;;;;kBAGc,MACpB;;;;;;;IAnC0E,CAAC;AAE9E,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;;;OAcG;SACE,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,WAAW;CAuCzD,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { JimpClassSchema } from "@jimp/types";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const MaskOptionsObjectSchema = z.object({
|
|
4
|
+
src: JimpClassSchema,
|
|
5
|
+
/** the x position to draw the image */
|
|
6
|
+
x: z.number().optional(),
|
|
7
|
+
/** the y position to draw the image */
|
|
8
|
+
y: z.number().optional(),
|
|
9
|
+
});
|
|
10
|
+
const MaskOptionsSchema = z.union([JimpClassSchema, MaskOptionsObjectSchema]);
|
|
11
|
+
export const methods = {
|
|
12
|
+
/**
|
|
13
|
+
* Masks a source image on to this image using average pixel colour. A completely black pixel on the mask will turn a pixel in the image completely transparent.
|
|
14
|
+
* @param src the source Jimp instance
|
|
15
|
+
* @param x the horizontal position to blit the image
|
|
16
|
+
* @param y the vertical position to blit the image
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { Jimp } from "jimp";
|
|
20
|
+
*
|
|
21
|
+
* const image = await Jimp.read("test/image.png");
|
|
22
|
+
* const mask = await Jimp.read("test/mask.png");
|
|
23
|
+
*
|
|
24
|
+
* image.mask(mask);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
mask(image, options) {
|
|
28
|
+
MaskOptionsSchema.parse(options);
|
|
29
|
+
let src;
|
|
30
|
+
let x;
|
|
31
|
+
let y;
|
|
32
|
+
if ("bitmap" in options) {
|
|
33
|
+
src = options;
|
|
34
|
+
x = 0;
|
|
35
|
+
y = 0;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
src = options.src;
|
|
39
|
+
x = options.x ?? 0;
|
|
40
|
+
y = options.y ?? 0;
|
|
41
|
+
}
|
|
42
|
+
// round input
|
|
43
|
+
x = Math.round(x);
|
|
44
|
+
y = Math.round(y);
|
|
45
|
+
const w = image.bitmap.width;
|
|
46
|
+
const h = image.bitmap.height;
|
|
47
|
+
src.scan(function (sx, sy, idx) {
|
|
48
|
+
const destX = x + sx;
|
|
49
|
+
const destY = y + sy;
|
|
50
|
+
if (destX >= 0 && destY >= 0 && destX < w && destY < h) {
|
|
51
|
+
const dstIdx = image.getPixelIndex(destX, destY);
|
|
52
|
+
const { data } = src.bitmap;
|
|
53
|
+
const avg = (data[idx + 0] + data[idx + 1] + data[idx + 2]) / 3;
|
|
54
|
+
image.bitmap.data[dstIdx + 3] *= avg / 255;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return image;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,GAAG,EAAE,eAAe;IACpB,uCAAuC;IACvC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxB,uCAAuC;IACvC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAAC,CAAC;AAI9E,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB;;;;;;;;;;;;;;OAcG;IACH,IAAI,CAAsB,KAAQ,EAAE,OAAoB;QACtD,iBAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEjC,IAAI,GAAc,CAAC;QACnB,IAAI,CAAS,CAAC;QACd,IAAI,CAAS,CAAC;QAEd,IAAI,QAAQ,IAAI,OAAO,EAAE,CAAC;YACxB,GAAG,GAAG,OAA+B,CAAC;YACtC,CAAC,GAAG,CAAC,CAAC;YACN,CAAC,GAAG,CAAC,CAAC;QACR,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,OAAO,CAAC,GAA2B,CAAC;YAC1C,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QAED,cAAc;QACd,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAElB,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;QAC7B,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;QAE9B,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,GAAG;YAC5B,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC;YAErB,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;gBACvD,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBACjD,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;gBAC5B,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,CAAC,GAAG,CAAC,CAAC;gBAEnE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,GAAG,GAAG,GAAG,CAAC;YAC7C,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/jimp__plugin-mask",
|
|
3
|
+
"version": "1.6.1-depup.30",
|
|
4
|
+
"repository": "jimp-dev/jimp",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"lint": "eslint .",
|
|
10
|
+
"test": "vitest",
|
|
11
|
+
"test:browser": "vitest --config vitest.config.browser.mjs",
|
|
12
|
+
"build": "tshy",
|
|
13
|
+
"dev": "tshy --watch",
|
|
14
|
+
"clean": "rm -rf node_modules .tshy .tshy-build dist .turbo"
|
|
15
|
+
},
|
|
16
|
+
"author": "Andrew Lisowski <lisowski54@gmail.com>",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@jimp/types": "1.6.1",
|
|
20
|
+
"zod": "^4.4.3"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@jimp/config-eslint": "1.6.1",
|
|
24
|
+
"@jimp/config-typescript": "1.6.1",
|
|
25
|
+
"@jimp/config-vitest": "1.6.1",
|
|
26
|
+
"@jimp/core": "1.6.1",
|
|
27
|
+
"@jimp/test-utils": "1.6.1",
|
|
28
|
+
"@vitest/browser": "^2.0.5",
|
|
29
|
+
"eslint": "^9.9.1",
|
|
30
|
+
"tshy": "^3.0.2",
|
|
31
|
+
"typescript": "^5.5.4",
|
|
32
|
+
"vite-plugin-node-polyfills": "^0.22.0",
|
|
33
|
+
"vitest": "^2.0.5"
|
|
34
|
+
},
|
|
35
|
+
"tshy": {
|
|
36
|
+
"exclude": [
|
|
37
|
+
"**/*.test.ts"
|
|
38
|
+
],
|
|
39
|
+
"exports": {
|
|
40
|
+
"./package.json": "./package.json",
|
|
41
|
+
".": "./src/index.ts"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
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
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"main": "./dist/commonjs/index.js",
|
|
58
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
59
|
+
"type": "module",
|
|
60
|
+
"sideEffects": false,
|
|
61
|
+
"module": "./dist/esm/index.js",
|
|
62
|
+
"gitHead": "7e6a95694e00a8b6f1bdd9aad709f5413eb9b08c",
|
|
63
|
+
"description": "@jimp/plugin-mask with all dependencies updated to latest",
|
|
64
|
+
"keywords": [
|
|
65
|
+
"@jimp/plugin-mask",
|
|
66
|
+
"depup",
|
|
67
|
+
"updated-dependencies",
|
|
68
|
+
"security",
|
|
69
|
+
"latest",
|
|
70
|
+
"patched"
|
|
71
|
+
],
|
|
72
|
+
"depup": {
|
|
73
|
+
"changes": {
|
|
74
|
+
"zod": {
|
|
75
|
+
"from": "^3.23.8",
|
|
76
|
+
"to": "^4.4.3"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"depsUpdated": 1,
|
|
80
|
+
"originalPackage": "@jimp/plugin-mask",
|
|
81
|
+
"originalVersion": "1.6.1",
|
|
82
|
+
"processedAt": "2026-07-21T19:29:08.313Z",
|
|
83
|
+
"smokeTest": "failed"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`Mask > Affect alpha image with a bigger gray mask 1`] = `
|
|
4
|
+
Visualization:
|
|
5
|
+
|
|
6
|
+
▴812
|
|
7
|
+
66▾▿
|
|
8
|
+
66▾▿
|
|
9
|
+
|
|
10
|
+
Data:
|
|
11
|
+
|
|
12
|
+
FF-00-00⁰⁰ FF-00-00²¹ 00-00-FF⁸⁸ 00-00-FF⁴³
|
|
13
|
+
FF-00-00⁸⁸ FF-00-00⁶⁵ 00-00-FFᶠᶠ 00-00-FF⁷ᶠ
|
|
14
|
+
FF-00-00⁸⁸ FF-00-00⁶⁵ 00-00-FFᶠᶠ 00-00-FF⁷ᶠ
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
exports[`Mask > Affect alpha image with a bigger gray mask, blited 1`] = `
|
|
18
|
+
Visualization:
|
|
19
|
+
|
|
20
|
+
4▵▾1
|
|
21
|
+
4▵▾1
|
|
22
|
+
8713
|
|
23
|
+
|
|
24
|
+
Data:
|
|
25
|
+
|
|
26
|
+
FF-00-00ᶜᶜ FF-00-00⁷ᶠ 00-00-FFᶠᶠ 00-00-FF⁶⁵
|
|
27
|
+
FF-00-00ᶜᶜ FF-00-00⁷ᶠ 00-00-FFᶠᶠ 00-00-FF⁶⁵
|
|
28
|
+
FF-00-00⁴⁴ FF-00-00⁴³ 00-00-FF⁸⁸ 00-00-FF²¹
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
exports[`Mask > Affect opaque image with a colored mask 1`] = `
|
|
32
|
+
Visualization:
|
|
33
|
+
|
|
34
|
+
▴□▾□■□
|
|
35
|
+
■!▿▰▿□
|
|
36
|
+
■C5C0□
|
|
37
|
+
■□■▴■▾
|
|
38
|
+
|
|
39
|
+
Data:
|
|
40
|
+
|
|
41
|
+
FF-00-00ᶠᶠ FF-FF-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-FFᶠᶠ 00-00-00ᶠᶠ FF-FF-FFᶠᶠ
|
|
42
|
+
00-00-00ᶠᶠ FF-00-00⁵⁵ 00-00-00⁵⁵ 00-00-FF⁵⁵ 00-00-00⁵⁵ FF-FF-FFᶠᶠ
|
|
43
|
+
00-00-00ᶠᶠ FF-FF-FFᵃᵃ FF-00-00ᵃᵃ FF-FF-FFᵃᵃ 00-00-FFᵃᵃ FF-FF-FFᶠᶠ
|
|
44
|
+
00-00-00ᶠᶠ FF-FF-FFᶠᶠ 00-00-00ᶠᶠ FF-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-FFᶠᶠ
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
exports[`Mask > Affect opaque image with a gray mask with the same size 1`] = `
|
|
48
|
+
Visualization:
|
|
49
|
+
|
|
50
|
+
▴F1DF0
|
|
51
|
+
D4■▾▥D
|
|
52
|
+
D▥▴□□D
|
|
53
|
+
FD6F5
|
|
54
|
+
|
|
55
|
+
Data:
|
|
56
|
+
|
|
57
|
+
FF-00-00⁰⁰ FF-FF-FF⁴⁴ 00-00-FF⁸⁸ FF-FF-FF⁸⁸ 00-00-00⁴⁴ FF-FF-FF⁰⁰
|
|
58
|
+
00-00-00⁸⁸ FF-00-00ᶜᶜ 00-00-00ᶠᶠ 00-00-FFᶠᶠ 00-00-00ᶜᶜ FF-FF-FF⁸⁸
|
|
59
|
+
00-00-00⁸⁸ FF-FF-FFᶜᶜ FF-00-00ᶠᶠ FF-FF-FFᶠᶠ 00-00-FFᶜᶜ FF-FF-FF⁸⁸
|
|
60
|
+
00-00-00⁰⁰ FF-FF-FF⁴⁴ 00-00-00⁸⁸ FF-00-00⁸⁸ 00-00-00⁴⁴ 00-00-FF⁰⁰
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
exports[`Mask > Affect opaque image with a gray mask with the same size, blited 1`] = `
|
|
64
|
+
Visualization:
|
|
65
|
+
|
|
66
|
+
▴□▾□■□
|
|
67
|
+
■▴F1DF
|
|
68
|
+
■D4□▾▥
|
|
69
|
+
■D▥▴■□
|
|
70
|
+
|
|
71
|
+
Data:
|
|
72
|
+
|
|
73
|
+
FF-00-00ᶠᶠ FF-FF-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-FFᶠᶠ 00-00-00ᶠᶠ FF-FF-FFᶠᶠ
|
|
74
|
+
00-00-00ᶠᶠ FF-00-00⁰⁰ 00-00-00⁴⁴ 00-00-FF⁸⁸ 00-00-00⁸⁸ FF-FF-FF⁴⁴
|
|
75
|
+
00-00-00ᶠᶠ FF-FF-FF⁸⁸ FF-00-00ᶜᶜ FF-FF-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-FFᶜᶜ
|
|
76
|
+
00-00-00ᶠᶠ FF-FF-FF⁸⁸ 00-00-00ᶜᶜ FF-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-FFᶜᶜ
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
exports[`Mask > Affect opaque image with a gray mask with the same size, blited negative 1`] = `
|
|
80
|
+
Visualization:
|
|
81
|
+
|
|
82
|
+
4□▾▥D□
|
|
83
|
+
▥▴■□D□
|
|
84
|
+
FD6F5□
|
|
85
|
+
■□■▴■▾
|
|
86
|
+
|
|
87
|
+
Data:
|
|
88
|
+
|
|
89
|
+
FF-00-00ᶜᶜ FF-FF-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-FFᶜᶜ 00-00-00⁸⁸ FF-FF-FFᶠᶠ
|
|
90
|
+
00-00-00ᶜᶜ FF-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-FFᶜᶜ 00-00-00⁸⁸ FF-FF-FFᶠᶠ
|
|
91
|
+
00-00-00⁴⁴ FF-FF-FF⁸⁸ FF-00-00⁸⁸ FF-FF-FF⁴⁴ 00-00-FF⁰⁰ FF-FF-FFᶠᶠ
|
|
92
|
+
00-00-00ᶠᶠ FF-FF-FFᶠᶠ 00-00-00ᶠᶠ FF-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-FFᶠᶠ
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
exports[`Mask > Affect opaque image with a smaller gray mask 1`] = `
|
|
96
|
+
Visualization:
|
|
97
|
+
|
|
98
|
+
▴◆2▹■□
|
|
99
|
+
◆7▹□■□
|
|
100
|
+
E▹4□▾□
|
|
101
|
+
■□■▴■▾
|
|
102
|
+
|
|
103
|
+
Data:
|
|
104
|
+
|
|
105
|
+
FF-00-00⁰⁰ FF-FF-FF³³ 00-00-FF⁶⁶ FF-FF-FF⁹⁹ 00-00-00ᶠᶠ FF-FF-FFᶠᶠ
|
|
106
|
+
00-00-00³³ FF-00-00⁶⁶ 00-00-00⁹⁹ 00-00-FFᶜᶜ 00-00-00ᶠᶠ FF-FF-FFᶠᶠ
|
|
107
|
+
00-00-00⁶⁶ FF-FF-FF⁹⁹ FF-00-00ᶜᶜ FF-FF-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-FFᶠᶠ
|
|
108
|
+
00-00-00ᶠᶠ FF-FF-FFᶠᶠ 00-00-00ᶠᶠ FF-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-FFᶠᶠ
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
exports[`Mask > Affect opaque image with a smaller gray mask, blited 1`] = `
|
|
112
|
+
Visualization:
|
|
113
|
+
|
|
114
|
+
▴□▾□■□
|
|
115
|
+
■▴◆2▹□
|
|
116
|
+
■◆7▹□□
|
|
117
|
+
■E▹4■▾
|
|
118
|
+
|
|
119
|
+
Data:
|
|
120
|
+
|
|
121
|
+
FF-00-00ᶠᶠ FF-FF-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-FFᶠᶠ 00-00-00ᶠᶠ FF-FF-FFᶠᶠ
|
|
122
|
+
00-00-00ᶠᶠ FF-00-00⁰⁰ 00-00-00³³ 00-00-FF⁶⁶ 00-00-00⁹⁹ FF-FF-FFᶠᶠ
|
|
123
|
+
00-00-00ᶠᶠ FF-FF-FF³³ FF-00-00⁶⁶ FF-FF-FF⁹⁹ 00-00-FFᶜᶜ FF-FF-FFᶠᶠ
|
|
124
|
+
00-00-00ᶠᶠ FF-FF-FF⁶⁶ 00-00-00⁹⁹ FF-00-00ᶜᶜ 00-00-00ᶠᶠ 00-00-FFᶠᶠ
|
|
125
|
+
`;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { expect, test, describe } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { makeTestImage } from "@jimp/test-utils";
|
|
4
|
+
import { createJimp } from "@jimp/core";
|
|
5
|
+
|
|
6
|
+
import { methods } from "./index.js";
|
|
7
|
+
|
|
8
|
+
const jimp = createJimp({ plugins: [methods] });
|
|
9
|
+
|
|
10
|
+
describe("Mask", () => {
|
|
11
|
+
const imgSrcOpaq = jimp.fromBitmap(
|
|
12
|
+
// prettier-ignore
|
|
13
|
+
makeTestImage(
|
|
14
|
+
"▴□▾□■□",
|
|
15
|
+
"■▴■▾■□",
|
|
16
|
+
"■□▴□▾□",
|
|
17
|
+
"■□■▴■▾"
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
const imgSrcAlpa = jimp.fromBitmap(
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
makeTestImage(
|
|
23
|
+
"▴▵▾▿",
|
|
24
|
+
"▴▵▾▿",
|
|
25
|
+
"▴▵▾▿"
|
|
26
|
+
),
|
|
27
|
+
);
|
|
28
|
+
const maskGrayBig = jimp.fromBitmap(
|
|
29
|
+
// prettier-ignore
|
|
30
|
+
makeTestImage(
|
|
31
|
+
"048840",
|
|
32
|
+
"8CFFC8",
|
|
33
|
+
"8CFFC8",
|
|
34
|
+
"048840"
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
const maskGraySmall = jimp.fromBitmap(
|
|
38
|
+
// prettier-ignore
|
|
39
|
+
makeTestImage(
|
|
40
|
+
"0369",
|
|
41
|
+
"369C",
|
|
42
|
+
"69CF"
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
const maskColor = jimp.fromBitmap(
|
|
46
|
+
// prettier-ignore
|
|
47
|
+
makeTestImage(
|
|
48
|
+
"▴▴▾▾",
|
|
49
|
+
"▪▪▰▰",
|
|
50
|
+
"□□□□"
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
test("Affect opaque image with a gray mask with the same size", () => {
|
|
55
|
+
expect(imgSrcOpaq.clone().mask(maskGrayBig)).toMatchSnapshot();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("Affect opaque image with a gray mask with the same size, blited", () => {
|
|
59
|
+
expect(
|
|
60
|
+
imgSrcOpaq.clone().mask({ src: maskGrayBig, x: 1, y: 1 }),
|
|
61
|
+
).toMatchSnapshot();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("Affect opaque image with a gray mask with the same size, blited negative", () => {
|
|
65
|
+
expect(
|
|
66
|
+
imgSrcOpaq.clone().mask({ src: maskGrayBig, x: -1, y: -1 }),
|
|
67
|
+
).toMatchSnapshot();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("Affect opaque image with a smaller gray mask", () => {
|
|
71
|
+
expect(imgSrcOpaq.clone().mask(maskGraySmall)).toMatchSnapshot();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("Affect opaque image with a smaller gray mask, blited", () => {
|
|
75
|
+
expect(
|
|
76
|
+
imgSrcOpaq.clone().mask({ src: maskGraySmall, x: 1, y: 1 }),
|
|
77
|
+
).toMatchSnapshot();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("Affect alpha image with a bigger gray mask", () => {
|
|
81
|
+
expect(imgSrcAlpa.clone().mask(maskGrayBig)).toMatchSnapshot();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("Affect alpha image with a bigger gray mask, blited", () => {
|
|
85
|
+
expect(
|
|
86
|
+
imgSrcAlpa.clone().mask({ src: maskGrayBig, x: -1, y: -1 }),
|
|
87
|
+
).toMatchSnapshot();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("Affect opaque image with a colored mask", () => {
|
|
91
|
+
expect(
|
|
92
|
+
imgSrcOpaq.clone().mask({ src: maskColor, x: 1, y: 1 }),
|
|
93
|
+
).toMatchSnapshot();
|
|
94
|
+
});
|
|
95
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { JimpClass, JimpClassSchema } from "@jimp/types";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
const MaskOptionsObjectSchema = z.object({
|
|
5
|
+
src: JimpClassSchema,
|
|
6
|
+
/** the x position to draw the image */
|
|
7
|
+
x: z.number().optional(),
|
|
8
|
+
/** the y position to draw the image */
|
|
9
|
+
y: z.number().optional(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const MaskOptionsSchema = z.union([JimpClassSchema, MaskOptionsObjectSchema]);
|
|
13
|
+
|
|
14
|
+
export type MaskOptions = z.infer<typeof MaskOptionsSchema>;
|
|
15
|
+
|
|
16
|
+
export const methods = {
|
|
17
|
+
/**
|
|
18
|
+
* Masks a source image on to this image using average pixel colour. A completely black pixel on the mask will turn a pixel in the image completely transparent.
|
|
19
|
+
* @param src the source Jimp instance
|
|
20
|
+
* @param x the horizontal position to blit the image
|
|
21
|
+
* @param y the vertical position to blit the image
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { Jimp } from "jimp";
|
|
25
|
+
*
|
|
26
|
+
* const image = await Jimp.read("test/image.png");
|
|
27
|
+
* const mask = await Jimp.read("test/mask.png");
|
|
28
|
+
*
|
|
29
|
+
* image.mask(mask);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
mask<I extends JimpClass>(image: I, options: MaskOptions) {
|
|
33
|
+
MaskOptionsSchema.parse(options);
|
|
34
|
+
|
|
35
|
+
let src: JimpClass;
|
|
36
|
+
let x: number;
|
|
37
|
+
let y: number;
|
|
38
|
+
|
|
39
|
+
if ("bitmap" in options) {
|
|
40
|
+
src = options as unknown as JimpClass;
|
|
41
|
+
x = 0;
|
|
42
|
+
y = 0;
|
|
43
|
+
} else {
|
|
44
|
+
src = options.src as unknown as JimpClass;
|
|
45
|
+
x = options.x ?? 0;
|
|
46
|
+
y = options.y ?? 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// round input
|
|
50
|
+
x = Math.round(x);
|
|
51
|
+
y = Math.round(y);
|
|
52
|
+
|
|
53
|
+
const w = image.bitmap.width;
|
|
54
|
+
const h = image.bitmap.height;
|
|
55
|
+
|
|
56
|
+
src.scan(function (sx, sy, idx) {
|
|
57
|
+
const destX = x + sx;
|
|
58
|
+
const destY = y + sy;
|
|
59
|
+
|
|
60
|
+
if (destX >= 0 && destY >= 0 && destX < w && destY < h) {
|
|
61
|
+
const dstIdx = image.getPixelIndex(destX, destY);
|
|
62
|
+
const { data } = src.bitmap;
|
|
63
|
+
const avg = (data[idx + 0]! + data[idx + 1]! + data[idx + 2]!) / 3;
|
|
64
|
+
|
|
65
|
+
image.bitmap.data[dstIdx + 3] *= avg / 255;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return image;
|
|
70
|
+
},
|
|
71
|
+
};
|
package/tsconfig.json
ADDED