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

> @jimp/plugin-circle@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/plugin-circle
> eslint .
+23
View File
@@ -0,0 +1,23 @@

> @jimp/plugin-circle@1.1.2 test:browser /Users/andrewlisowski/Documents/jimp/plugins/plugin-circle
> vitest --config vitest.config.browser.mjs "--watch=false"
Re-optimizing dependencies because lockfile has changed
Port 5173 is in use, trying another one...
Port 5174 is in use, trying another one...
Port 5175 is in use, trying another one...
Port 5176 is in use, trying another one...
 RUN  v2.0.5 /Users/andrewlisowski/Documents/jimp/plugins/plugin-circle
 Browser runner started at http://localhost:5177/
1:39:27 AM [vite] error while updating dependencies:
Error: The service was stopped
at /Users/andrewlisowski/Documents/jimp/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:993:26
at responseCallbacks.<computed> (/Users/andrewlisowski/Documents/jimp/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:622:9)
at Socket.afterClose (/Users/andrewlisowski/Documents/jimp/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:613:28)
at Socket.emit (node:events:529:35)
at endReadableNT (node:internal/streams/readable:1400:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
 ELIFECYCLE  Command failed with exit code 130.
+30
View File
@@ -0,0 +1,30 @@

> @jimp/plugin-circle@1.1.2 test /Users/andrewlisowski/Documents/jimp/plugins/plugin-circle
> vitest "--watch=false"
 RUN  v2.0.5 /Users/andrewlisowski/Documents/jimp/plugins/plugin-circle
[?25l · src/index.test.ts (3)
· Circle (3)
· makes a circle based on image height and width
· makes a circle using provided radius
· should
[?25l[?25l ✓ src/index.test.ts (3)
✓ Circle (3)
✓ makes a circle based on image height and width
✓ makes a circle using provided radius
✓ should
 ✓ src/index.test.ts (3)
✓ Circle (3)
✓ makes a circle based on image height and width
✓ makes a circle using provided radius
✓ should
 Test Files  1 passed (1)
 Tests  3 passed (3)
 Start at  01:33:39
 Duration  2.52s (transform 449ms, setup 0ms, collect 761ms, tests 27ms, environment 0ms, prepare 440ms)
[?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-circle</h1>
<p>Creates a circle out of an image.</p>
</div>
- [circle](http://jimp-dev.github.io/jimp/api/jimp/classes/jimp#circle)
+37
View File
@@ -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
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;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"}
+49
View File
@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.methods = void 0;
const zod_1 = require("zod");
const CircleOptionsSchema = zod_1.z.object({
/** the x position to draw the circle */
x: zod_1.z.number().optional(),
/** the y position to draw the circle */
y: zod_1.z.number().optional(),
/** the radius of the circle */
radius: zod_1.z.number().min(0).optional(),
});
exports.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
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AAExB,MAAM,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IACnC,wCAAwC;IACxC,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxB,wCAAwC;IACxC,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxB,+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;;;;;;;;;;;;OAYG;IACH,MAAM,CAAsB,KAAQ,EAAE,UAAyB,EAAE;QAC/D,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,MAAM,GACV,MAAM,CAAC,MAAM;YACb,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM;gBACvC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM;gBACrB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE9B,MAAM,MAAM,GAAG;YACb,CAAC,EAAE,OAAO,MAAM,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC;YACnE,CAAC,EAAE,OAAO,MAAM,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;SACrE,CAAC;QAEF,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;YACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CACpB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CACtD,CAAC;YAEF,IAAI,MAAM,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC;gBACzB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC;iBAAM,IAAI,MAAM,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC;gBAC/B,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+37
View File
@@ -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
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;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
View File
@@ -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
View File
@@ -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,CAAC,MAAM,CAAC;IACnC,wCAAwC;IACxC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxB,wCAAwC;IACxC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxB,+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;;;;;;;;;;;;OAYG;IACH,MAAM,CAAsB,KAAQ,EAAE,UAAyB,EAAE;QAC/D,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,MAAM,GACV,MAAM,CAAC,MAAM;YACb,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM;gBACvC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM;gBACrB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE9B,MAAM,MAAM,GAAG;YACb,CAAC,EAAE,OAAO,MAAM,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC;YACnE,CAAC,EAAE,OAAO,MAAM,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;SACrE,CAAC;QAEF,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;YACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CACpB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CACtD,CAAC;YAEF,IAAI,MAAM,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC;gBACzB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC;iBAAM,IAAI,MAAM,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC;gBAC/B,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "module"
}
+2
View File
@@ -0,0 +1,2 @@
import shared from "@jimp/config-eslint/base.js";
export default [...shared];
+66
View File
@@ -0,0 +1,66 @@
{
"name": "@jimp/plugin-circle",
"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",
"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"
}
+85
View File
@@ -0,0 +1,85 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Circle > makes a circle based on image height and width 1`] = `
Visualization:
▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾8A▦A8▾▾▾▾▾▾▾
▾▾▾▾▾▾▾E▦▦▦▦▦E▾▾▾▾▾▾
▾▾▾▾▾▾8▦▦▦▦▦▦▦8▾▾▾▾▾
▾▾▾▾▾▾A▦▦▦▦▦▦▦A▾▾▾▾▾
▾▾▾▾▾▾▦▦▦▦▦▦▦▦▦▾▾▾▾▾
▾▾▾▾▾▾A▦▦▦▦▦▦▦A▾▾▾▾▾
▾▾▾▾▾▾8▦▦▦▦▦▦▦8▾▾▾▾▾
▾▾▾▾▾▾▾E▦▦▦▦▦E▾▾▾▾▾▾
▾▾▾▾▾▾▾▾8A▦A8▾▾▾▾▾▾▾
Data:
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁸⁶ 80-80-80ᵈᶠ 80-80-80ᶠᶠ 80-80-80ᵈᶠ 80-80-80⁸⁶ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᶜ¹ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶜ¹ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁸⁶ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80⁸⁶ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᵈᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᵈᶠ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᵈᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᵈᶠ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁸⁶ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80⁸⁶ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᶜ¹ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶜ¹ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁸⁶ 80-80-80ᵈᶠ 80-80-80ᶠᶠ 80-80-80ᵈᶠ 80-80-80⁸⁶ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
`;
exports[`Circle > makes a circle using provided radius 1`] = `
Visualization:
▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾ F▦F ▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾F▦▦▦F▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾▦▦▦▦▦▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾F▦▦▦F▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾ F▦F ▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾
▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾
Data:
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80²ᵇ 80-80-80ᶜ² 80-80-80ᶠᶠ 80-80-80ᶜ² 80-80-80²ᵇ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᶜ² 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶜ² 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᶜ² 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶜ² 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80²ᵇ 80-80-80ᶜ² 80-80-80ᶠᶠ 80-80-80ᶜ² 80-80-80²ᵇ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
`;
exports[`Circle > should 1`] = `
Visualization:
▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾▾
▾▾▾8A▦A8▾▾▾▾▾▾▾▾▾▾▾▾
▾▾E▦▦▦▦▦E▾▾▾▾▾▾▾▾▾▾▾
▾8▦▦▦▦▦▦▦8▾▾▾▾▾▾▾▾▾▾
▾A▦▦▦▦▦▦▦A▾▾▾▾▾▾▾▾▾▾
▾▦▦▦▦▦▦▦▦▦▾▾▾▾▾▾▾▾▾▾
▾A▦▦▦▦▦▦▦A▾▾▾▾▾▾▾▾▾▾
▾8▦▦▦▦▦▦▦8▾▾▾▾▾▾▾▾▾▾
▾▾E▦▦▦▦▦E▾▾▾▾▾▾▾▾▾▾▾
▾▾▾8A▦A8▾▾▾▾▾▾▾▾▾▾▾▾
Data:
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁸⁶ 80-80-80ᵈᶠ 80-80-80ᶠᶠ 80-80-80ᵈᶠ 80-80-80⁸⁶ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᶜ¹ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶜ¹ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁸⁶ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80⁸⁶ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80ᵈᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᵈᶠ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80ᵈᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᵈᶠ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁸⁶ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80⁸⁶ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80ᶜ¹ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶠᶠ 80-80-80ᶜ¹ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁸⁶ 80-80-80ᵈᶠ 80-80-80ᶠᶠ 80-80-80ᵈᶠ 80-80-80⁸⁶ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰ 80-80-80⁰⁰
`;
+67
View File
@@ -0,0 +1,67 @@
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("Circle", () => {
test("makes a circle based on image height and width", () => {
const imgSrc = Jimp.fromBitmap(
makeTestImage(
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
),
);
expect(imgSrc.circle()).toMatchSnapshot();
});
test("makes a circle using provided radius", () => {
const imgSrc = Jimp.fromBitmap(
makeTestImage(
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
),
);
expect(imgSrc.circle({ radius: 3 })).toMatchSnapshot();
});
test("should ", () => {
const imgSrc = Jimp.fromBitmap(
makeTestImage(
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
"▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦",
),
);
expect(imgSrc.circle({ radius: 5, x: 5, y: 5 })).toMatchSnapshot();
});
});
+56
View File
@@ -0,0 +1,56 @@
import { JimpClass } from "@jimp/types";
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 type CircleOptions = z.infer<typeof CircleOptionsSchema>;
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<I extends JimpClass>(image: I, options: CircleOptions = {}) {
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;
},
};
+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;