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

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

> @jimp/plugin-flip@1.1.2 test:browser /Users/andrewlisowski/Documents/jimp/plugins/plugin-flip
> vitest --config vitest.config.browser.mjs "--watch=false"
+30
View File
@@ -0,0 +1,30 @@

> @jimp/plugin-flip@1.1.2 test /Users/andrewlisowski/Documents/jimp/plugins/plugin-flip
> vitest "--watch=false"
 RUN  v2.0.5 /Users/andrewlisowski/Documents/jimp/plugins/plugin-flip
[?25l · src/index.test.ts (3)
· Flipping plugin (3)
· can flip horizontally
· can flip vertically
· can flip both horizontally and vertically at once
[?25l ✓ src/index.test.ts (3)
✓ Flipping plugin (3)
✓ can flip horizontally
✓ can flip vertically
✓ can flip both horizontally and vertically at once
[?25l[?25l ✓ src/index.test.ts (3)
✓ Flipping plugin (3)
✓ can flip horizontally
✓ can flip vertically
✓ can flip both horizontally and vertically at once
 Test Files  1 passed (1)
 Tests  3 passed (3)
 Start at  01:33:33
 Duration  2.83s (transform 997ms, setup 0ms, collect 1.36s, tests 5ms, environment 0ms, prepare 570ms)
[?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.
+13
View File
@@ -0,0 +1,13 @@
<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-flip</h1>
<p>flip an image.</p>
</div>
Flip the image horizontally or vertically. Defaults to horizontal.
Also aliased as `mirror`
- [flip](http://jimp-dev.github.io/jimp/api/jimp/classes/jimp#flip)
- [mirror](http://jimp-dev.github.io/jimp/api/jimp/classes/jimp#mirror)
+33
View File
@@ -0,0 +1,33 @@
import { JimpClass } from "@jimp/types";
import { z } from "zod";
declare const FlipOptionsSchema: z.ZodObject<{
/** if true the image will be flipped horizontally */
horizontal: z.ZodOptional<z.ZodBoolean>;
/** if true the image will be flipped vertically */
vertical: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
horizontal?: boolean | undefined;
vertical?: boolean | undefined;
}, {
horizontal?: boolean | undefined;
vertical?: boolean | undefined;
}>;
export type FlipOptions = z.infer<typeof FlipOptionsSchema>;
export declare const methods: {
/**
* Flip the image.
* @param horizontal a Boolean, if true the image will be flipped horizontally
* @param vertical a Boolean, if true the image will be flipped vertically
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.flip(true, false);
* ```
*/
flip<I extends JimpClass>(image: I, options: FlipOptions): 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,iBAAiB;IACrB,qDAAqD;;IAErD,mDAAmD;;;;;;;;EAEnD,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;OAYG;SACE,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,WAAW;CAiBzD,CAAC"}
+39
View File
@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.methods = void 0;
const zod_1 = require("zod");
const FlipOptionsSchema = zod_1.z.object({
/** if true the image will be flipped horizontally */
horizontal: zod_1.z.boolean().optional(),
/** if true the image will be flipped vertically */
vertical: zod_1.z.boolean().optional(),
});
exports.methods = {
/**
* Flip the image.
* @param horizontal a Boolean, if true the image will be flipped horizontally
* @param vertical a Boolean, if true the image will be flipped vertically
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.flip(true, false);
* ```
*/
flip(image, options) {
const { horizontal, vertical } = FlipOptionsSchema.parse(options);
const bitmap = Buffer.alloc(image.bitmap.data.length);
image.scan((x, y, idx) => {
const _x = horizontal ? image.bitmap.width - 1 - x : x;
const _y = vertical ? image.bitmap.height - 1 - y : y;
const _idx = (image.bitmap.width * _y + _x) << 2;
const data = image.bitmap.data.readUInt32BE(idx);
bitmap.writeUInt32BE(data, _idx);
});
image.bitmap.data = Buffer.from(bitmap);
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,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACjC,qDAAqD;IACrD,UAAU,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAClC,mDAAmD;IACnD,QAAQ,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC;AAIU,QAAA,OAAO,GAAG;IACrB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAsB,KAAQ,EAAE,OAAoB;QACtD,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,iBAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEtD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;YACvB,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACvD,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;YACjD,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAEjD,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAExC,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+33
View File
@@ -0,0 +1,33 @@
import { JimpClass } from "@jimp/types";
import { z } from "zod";
declare const FlipOptionsSchema: z.ZodObject<{
/** if true the image will be flipped horizontally */
horizontal: z.ZodOptional<z.ZodBoolean>;
/** if true the image will be flipped vertically */
vertical: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
horizontal?: boolean | undefined;
vertical?: boolean | undefined;
}, {
horizontal?: boolean | undefined;
vertical?: boolean | undefined;
}>;
export type FlipOptions = z.infer<typeof FlipOptionsSchema>;
export declare const methods: {
/**
* Flip the image.
* @param horizontal a Boolean, if true the image will be flipped horizontally
* @param vertical a Boolean, if true the image will be flipped vertically
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.flip(true, false);
* ```
*/
flip<I extends JimpClass>(image: I, options: FlipOptions): 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,iBAAiB;IACrB,qDAAqD;;IAErD,mDAAmD;;;;;;;;EAEnD,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;OAYG;SACE,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,WAAW;CAiBzD,CAAC"}
+36
View File
@@ -0,0 +1,36 @@
import { z } from "zod";
const FlipOptionsSchema = z.object({
/** if true the image will be flipped horizontally */
horizontal: z.boolean().optional(),
/** if true the image will be flipped vertically */
vertical: z.boolean().optional(),
});
export const methods = {
/**
* Flip the image.
* @param horizontal a Boolean, if true the image will be flipped horizontally
* @param vertical a Boolean, if true the image will be flipped vertically
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.flip(true, false);
* ```
*/
flip(image, options) {
const { horizontal, vertical } = FlipOptionsSchema.parse(options);
const bitmap = Buffer.alloc(image.bitmap.data.length);
image.scan((x, y, idx) => {
const _x = horizontal ? image.bitmap.width - 1 - x : x;
const _y = vertical ? image.bitmap.height - 1 - y : y;
const _idx = (image.bitmap.width * _y + _x) << 2;
const data = image.bitmap.data.readUInt32BE(idx);
bitmap.writeUInt32BE(data, _idx);
});
image.bitmap.data = Buffer.from(bitmap);
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,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,qDAAqD;IACrD,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAClC,mDAAmD;IACnD,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAsB,KAAQ,EAAE,OAAoB;QACtD,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,iBAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEtD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;YACvB,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACvD,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;YACjD,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAEjD,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAExC,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];
+67
View File
@@ -0,0 +1,67 @@
{
"name": "@jimp/plugin-flip",
"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",
"@types/node": "^18.19.48",
"@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"
}
+67
View File
@@ -0,0 +1,67 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Flipping plugin > can flip both horizontally and vertically at once 1`] = `
Visualization:
AACCCCAA
CCCCCCCC
CCCCCCCC
CCCCCCCC
BABABABA
BAAABAAA
BBBBAAAA
Data:
AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ
CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ
CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ
CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ
BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ
BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ
BB-BB-BBᶠᶠ BB-BB-BBᶠᶠ BB-BB-BBᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ
`;
exports[`Flipping plugin > can flip horizontally 1`] = `
Visualization:
BBBBAAAA
BAAABAAA
BABABABA
CCCCCCCC
CCCCCCCC
CCCCCCCC
AACCCCAA
Data:
BB-BB-BBᶠᶠ BB-BB-BBᶠᶠ BB-BB-BBᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ
BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ
BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ
CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ
CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ
CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ
AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ
`;
exports[`Flipping plugin > can flip vertically 1`] = `
Visualization:
AACCCCAA
CCCCCCCC
CCCCCCCC
CCCCCCCC
ABABABAB
AAABAAAB
AAAABBBB
Data:
AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ
CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ
CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ
CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ CC-CC-CCᶠᶠ
AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ
AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ
AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ AA-AA-AAᶠᶠ BB-BB-BBᶠᶠ BB-BB-BBᶠᶠ BB-BB-BBᶠᶠ BB-BB-BBᶠᶠ
`;
+57
View File
@@ -0,0 +1,57 @@
import { describe, expect, test } from "vitest";
import { createJimp } from "@jimp/core";
import { makeTestImage } from "@jimp/test-utils";
import { methods } from "./index.js";
const jimp = createJimp({ plugins: [methods] });
describe("Flipping plugin", () => {
test("can flip horizontally", () => {
const src = jimp.fromBitmap(
makeTestImage(
"AAAABBBB",
"AAABAAAB",
"ABABABAB",
"CCCCCCCC",
"CCCCCCCC",
"CCCCCCCC",
"AACCCCAA",
),
);
expect(src.flip({ horizontal: true })).toMatchSnapshot();
});
test("can flip vertically", () => {
const src = jimp.fromBitmap(
makeTestImage(
"AAAABBBB",
"AAABAAAB",
"ABABABAB",
"CCCCCCCC",
"CCCCCCCC",
"CCCCCCCC",
"AACCCCAA",
),
);
expect(src.flip({ vertical: true })).toMatchSnapshot();
});
test("can flip both horizontally and vertically at once", async () => {
const src = jimp.fromBitmap(
makeTestImage(
"AAAABBBB",
"AAABAAAB",
"ABABABAB",
"CCCCCCCC",
"CCCCCCCC",
"CCCCCCCC",
"AACCCCAA",
),
);
expect(src.flip({ horizontal: true, vertical: true })).toMatchSnapshot();
});
});
+44
View File
@@ -0,0 +1,44 @@
import { JimpClass } from "@jimp/types";
import { z } from "zod";
const FlipOptionsSchema = z.object({
/** if true the image will be flipped horizontally */
horizontal: z.boolean().optional(),
/** if true the image will be flipped vertically */
vertical: z.boolean().optional(),
});
export type FlipOptions = z.infer<typeof FlipOptionsSchema>;
export const methods = {
/**
* Flip the image.
* @param horizontal a Boolean, if true the image will be flipped horizontally
* @param vertical a Boolean, if true the image will be flipped vertically
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.flip(true, false);
* ```
*/
flip<I extends JimpClass>(image: I, options: FlipOptions) {
const { horizontal, vertical } = FlipOptionsSchema.parse(options);
const bitmap = Buffer.alloc(image.bitmap.data.length);
image.scan((x, y, idx) => {
const _x = horizontal ? image.bitmap.width - 1 - x : x;
const _y = vertical ? image.bitmap.height - 1 - y : y;
const _idx = (image.bitmap.width * _y + _x) << 2;
const data = image.bitmap.data.readUInt32BE(idx);
bitmap.writeUInt32BE(data, _idx);
});
image.bitmap.data = Buffer.from(bitmap);
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;