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-fisheye@1.5.0 build /Users/andrewlisowski/Documents/jimp/plugins/plugin-fisheye
> tshy
+5
View File
@@ -0,0 +1,5 @@

> @jimp/plugin-fisheye@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/plugin-fisheye
> eslint .
@@ -0,0 +1,2 @@

+23
View File
@@ -0,0 +1,23 @@

> @jimp/plugin-fisheye@1.1.2 test /Users/andrewlisowski/Documents/jimp/plugins/plugin-fisheye
> vitest "--watch=false"
 RUN  v2.0.5 /Users/andrewlisowski/Documents/jimp/plugins/plugin-fisheye
[?25l ✓ src/index.test.ts (2)
✓ Fisheye (2)
✓ should create fisheye lens to image
✓ should create fisheye lens to image with radius
[?25l ✓ src/index.test.ts (2)
✓ Fisheye (2)
✓ should create fisheye lens to image
✓ should create fisheye lens to image with radius
 Test Files  1 passed (1)
 Tests  2 passed (2)
 Start at  01:33:44
 Duration  2.06s (transform 724ms, setup 0ms, collect 1.41s, tests 4ms, environment 0ms, prepare 145ms)
[?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.
+8
View File
@@ -0,0 +1,8 @@
<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-fisheye</h1>
<p>Apply a fisheye effect to an image</p>
</div>
- [fisheye](http://jimp-dev.github.io/jimp/api/jimp/classes/jimp#fisheye)
+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,EA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C,aAAa,CACjB,MAAM,CAAC,aAAa,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,EAC3C,KAAK,GAAG,CAAC,EACT,MAAM,GAAG,CAAC,CACX,CAAC;QAEF,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+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"}
+40
View File
@@ -0,0 +1,40 @@
import { clone } from "@jimp/utils";
import { z } from "zod";
const FisheyeOptionsSchema = z.object({
/** the radius of the circle */
radius: z.number().min(0).optional(),
});
export 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(image, options = {}) {
const { radius = 2.5 } = FisheyeOptionsSchema.parse(options);
const source = 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,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,+BAA+B;IAC/B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,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,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC;QAExC,MAAM,CAAC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
}
+2
View File
@@ -0,0 +1,2 @@
import shared from "@jimp/config-eslint/base.js";
export default [...shared];
+67
View File
@@ -0,0 +1,67 @@
{
"name": "@jimp/plugin-fisheye",
"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",
"dependencies": {
"@jimp/types": "1.6.0",
"@jimp/utils": "1.6.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@jimp/config-eslint": "1.6.0",
"@jimp/config-typescript": "1.6.0",
"@jimp/config-vitest": "1.6.0",
"@jimp/core": "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"
},
"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"
}
+57
View File
@@ -0,0 +1,57 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Fisheye > should create fisheye lens to image 1`] = `
Visualization:
■■■1221■■■
■22111222■
■22■■■■121
11■■■■■112
21■■■■■■12
21■■■■■■12
12■■■■■■12
■211■■■222
■22111122■
■■122222■■
Data:
00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 11-11-11ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 22-22-22ᶠᶠ 11-11-11ᶠᶠ
11-11-11ᶠᶠ 11-11-11ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 22-22-22ᶠᶠ
22-22-22ᶠᶠ 11-11-11ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 22-22-22ᶠᶠ
22-22-22ᶠᶠ 11-11-11ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 22-22-22ᶠᶠ
11-11-11ᶠᶠ 22-22-22ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 22-22-22ᶠᶠ
00-00-00ᶠᶠ 22-22-22ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ
00-00-00ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 22-22-22ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
`;
exports[`Fisheye > should create fisheye lens to image with radius 1`] = `
Visualization:
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■11111■■
■■111111■■
■■111111■■
■■■■111■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
Data:
00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 11-11-11ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ 00-00-00ᶠᶠ
`;
+48
View File
@@ -0,0 +1,48 @@
import { expect, test, describe } from "vitest";
import { makeTestImage } from "@jimp/test-utils";
import { createJimp } from "@jimp/core";
import { methods } from "./index.js";
const Jimp = createJimp({ plugins: [methods] });
describe("Fisheye", () => {
test("should create fisheye lens to image", () => {
const img = Jimp.fromBitmap(
makeTestImage(
"0000000000",
"0001221000",
"0022222200",
"0122112210",
"0221001220",
"0221001220",
"0122112210",
"0022222200",
"0001221000",
"0000000000",
),
);
expect(img.fisheye()).toMatchSnapshot();
});
test("should create fisheye lens to image with radius", async () => {
const imgNormal = Jimp.fromBitmap(
makeTestImage(
"0000000000",
"0000000000",
"0000000000",
"0000000000",
"0001111000",
"0001111000",
"0000000000",
"0000000000",
"0000000000",
"0000000000",
),
);
expect(imgNormal.fisheye({ radius: 1.8 })).toMatchSnapshot();
});
});
+52
View File
@@ -0,0 +1,52 @@
import { JimpClass } from "@jimp/types";
import { clone } from "@jimp/utils";
import { z } from "zod";
const FisheyeOptionsSchema = z.object({
/** the radius of the circle */
radius: z.number().min(0).optional(),
});
export type FisheyeOptions = z.infer<typeof FisheyeOptionsSchema>;
export 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 = {}) {
const { radius = 2.5 } = FisheyeOptionsSchema.parse(options);
const source = 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;
},
};
+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;