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

+102
View File
@@ -0,0 +1,102 @@
import { JimpClass } from "@jimp/types";
import { z } from "zod";
declare const MaskOptionsSchema: z.ZodUnion<[z.ZodObject<{
bitmap: z.ZodObject<{
data: z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
width: z.ZodNumber;
height: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
data: Buffer | Uint8Array;
width: number;
height: number;
}, {
data: Buffer | Uint8Array;
width: number;
height: number;
}>;
}, "strip", z.ZodTypeAny, {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
}, {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
}>, z.ZodObject<{
src: z.ZodObject<{
bitmap: z.ZodObject<{
data: z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
width: z.ZodNumber;
height: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
data: Buffer | Uint8Array;
width: number;
height: number;
}, {
data: Buffer | Uint8Array;
width: number;
height: number;
}>;
}, "strip", z.ZodTypeAny, {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
}, {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
}>;
/** the x position to draw the image */
x: z.ZodOptional<z.ZodNumber>;
/** the y position to draw the image */
y: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
src: {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
};
x?: number | undefined;
y?: number | undefined;
}, {
src: {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
};
x?: number | undefined;
y?: number | undefined;
}>]>;
export type MaskOptions = z.infer<typeof MaskOptionsSchema>;
export declare const methods: {
/**
* 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.
* @param src the source Jimp instance
* @param x the horizontal position to blit the image
* @param y the vertical position to blit the image
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
* const mask = await Jimp.read("test/mask.png");
*
* image.mask(mask);
* ```
*/
mask<I extends JimpClass>(image: I, options: MaskOptions): 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,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"}
+63
View File
@@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.methods = void 0;
const types_1 = require("@jimp/types");
const zod_1 = require("zod");
const MaskOptionsObjectSchema = zod_1.z.object({
src: types_1.JimpClassSchema,
/** the x position to draw the image */
x: zod_1.z.number().optional(),
/** the y position to draw the image */
y: zod_1.z.number().optional(),
});
const MaskOptionsSchema = zod_1.z.union([types_1.JimpClassSchema, MaskOptionsObjectSchema]);
exports.methods = {
/**
* 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.
* @param src the source Jimp instance
* @param x the horizontal position to blit the image
* @param y the vertical position to blit the image
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
* const mask = await Jimp.read("test/mask.png");
*
* image.mask(mask);
* ```
*/
mask(image, options) {
MaskOptionsSchema.parse(options);
let src;
let x;
let y;
if ("bitmap" in options) {
src = options;
x = 0;
y = 0;
}
else {
src = options.src;
x = options.x ?? 0;
y = options.y ?? 0;
}
// round input
x = Math.round(x);
y = Math.round(y);
const w = image.bitmap.width;
const h = image.bitmap.height;
src.scan(function (sx, sy, idx) {
const destX = x + sx;
const destY = y + sy;
if (destX >= 0 && destY >= 0 && destX < w && destY < h) {
const dstIdx = image.getPixelIndex(destX, destY);
const { data } = src.bitmap;
const avg = (data[idx + 0] + data[idx + 1] + data[idx + 2]) / 3;
image.bitmap.data[dstIdx + 3] *= avg / 255;
}
});
return image;
},
};
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +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;Q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