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

+27
View File
@@ -0,0 +1,27 @@
import { JimpClass } from "@jimp/types";
import { z } from "zod";
declare const FisheyeOptionsSchema: z.ZodObject<{
/** the radius of the circle */
radius: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
radius?: number | undefined;
}, {
radius?: number | undefined;
}>;
export type FisheyeOptions = z.infer<typeof FisheyeOptionsSchema>;
export declare const methods: {
/**
* Adds a fisheye effect to the image.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.fisheye();
* ```
*/
fisheye<I extends JimpClass>(image: I, options?: FisheyeOptions): 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;AAExC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,oBAAoB;IACxB,+BAA+B;;;;;;EAE/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;OAUG;YACK,CAAC,SAAS,SAAS,SAAS,CAAC,YAAW,cAAc;CA4B/D,CAAC"}
+43
View File
@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.methods = void 0;
const utils_1 = require("@jimp/utils");
const zod_1 = require("zod");
const FisheyeOptionsSchema = zod_1.z.object({
/** the radius of the circle */
radius: zod_1.z.number().min(0).optional(),
});
exports.methods = {
/**
* Adds a fisheye effect to the image.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.fisheye();
* ```
*/
fisheye(image, options = {}) {
const { radius = 2.5 } = FisheyeOptionsSchema.parse(options);
const source = (0, utils_1.clone)(image);
const { width, height } = source.bitmap;
source.scan((x, y) => {
const hx = x / width;
const hy = y / height;
const rActual = Math.sqrt(Math.pow(hx - 0.5, 2) + Math.pow(hy - 0.5, 2));
const rn = 2 * Math.pow(rActual, radius);
const cosA = (hx - 0.5) / rActual;
const sinA = (hy - 0.5) / rActual;
const newX = Math.round((rn * cosA + 0.5) * width);
const newY = Math.round((rn * sinA + 0.5) * height);
const color = source.getPixelColor(newX, newY);
image.setPixelColor(color, x, y);
});
/* Set center pixel color, otherwise it will be transparent */
image.setPixelColor(source.getPixelColor(width / 2, height / 2), width / 2, height / 2);
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,uCAAoC;AACpC,6BAAwB;AAExB,MAAM,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IACpC,+BAA+B;IAC/B,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAC;AAIU,QAAA,OAAO,GAAG;IACrB;;;;;;;;;;OAUG;IACH,OAAO,CAAsB,KAAQ,EAAE,UAA0B,EAAE;QACjE,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,GAAG,oBAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7D,MAAM,MAAM,GAAG,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;QAC5B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC;QAExC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACnB,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC;YACrB,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC;YACtB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