Initial commit
This commit is contained in:
commit
e49726988c
5445 files changed
+1089914
No files matched your search
+37
@@ -0,0 +1,37 @@
|
||||
import { JimpClass } from "@jimp/types";
|
||||
import { z } from "zod";
|
||||
declare const CircleOptionsSchema: z.ZodObject<{
|
||||
/** the x position to draw the circle */
|
||||
x: z.ZodOptional<z.ZodNumber>;
|
||||
/** the y position to draw the circle */
|
||||
y: z.ZodOptional<z.ZodNumber>;
|
||||
/** the radius of the circle */
|
||||
radius: z.ZodOptional<z.ZodNumber>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
x?: number | undefined;
|
||||
y?: number | undefined;
|
||||
radius?: number | undefined;
|
||||
}, {
|
||||
x?: number | undefined;
|
||||
y?: number | undefined;
|
||||
radius?: number | undefined;
|
||||
}>;
|
||||
export type CircleOptions = z.infer<typeof CircleOptionsSchema>;
|
||||
export declare const methods: {
|
||||
/**
|
||||
* Creates a circle out of an image.
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Jimp } from "jimp";
|
||||
*
|
||||
* const image = await Jimp.read("test/image.png");
|
||||
*
|
||||
* image.circle();
|
||||
* // or
|
||||
* image.circle({ radius: 50, x: 25, y: 25 });
|
||||
* ```
|
||||
*/
|
||||
circle<I extends JimpClass>(image: I, options?: CircleOptions): I;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,mBAAmB;IACvB,wCAAwC;;IAExC,wCAAwC;;IAExC,+BAA+B;;;;;;;;;;EAE/B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;OAYG;WACI,CAAC,SAAS,SAAS,SAAS,CAAC,YAAW,aAAa;CA2B7D,CAAC"}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import { z } from "zod";
|
||||
const CircleOptionsSchema = z.object({
|
||||
/** the x position to draw the circle */
|
||||
x: z.number().optional(),
|
||||
/** the y position to draw the circle */
|
||||
y: z.number().optional(),
|
||||
/** the radius of the circle */
|
||||
radius: z.number().min(0).optional(),
|
||||
});
|
||||
export const methods = {
|
||||
/**
|
||||
* Creates a circle out of an image.
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Jimp } from "jimp";
|
||||
*
|
||||
* const image = await Jimp.read("test/image.png");
|
||||
*
|
||||
* image.circle();
|
||||
* // or
|
||||
* image.circle({ radius: 50, x: 25, y: 25 });
|
||||
* ```
|
||||
*/
|
||||
circle(image, options = {}) {
|
||||
const parsed = CircleOptionsSchema.parse(options);
|
||||
const radius = parsed.radius ||
|
||||
(image.bitmap.width > image.bitmap.height
|
||||
? image.bitmap.height
|
||||
: image.bitmap.width) / 2;
|
||||
const center = {
|
||||
x: typeof parsed.x === "number" ? parsed.x : image.bitmap.width / 2,
|
||||
y: typeof parsed.y === "number" ? parsed.y : image.bitmap.height / 2,
|
||||
};
|
||||
image.scan((x, y, idx) => {
|
||||
const curR = Math.sqrt(Math.pow(x - center.x, 2) + Math.pow(y - center.y, 2));
|
||||
if (radius - curR <= 0.0) {
|
||||
image.bitmap.data[idx + 3] = 0;
|
||||
}
|
||||
else if (radius - curR < 1.0) {
|
||||
image.bitmap.data[idx + 3] = 255 * (radius - curR);
|
||||
}
|
||||
});
|
||||
return image;
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,mBAAmB,GAAG,CAAC,CAA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