Initial commit
This commit is contained in:
commit
e49726988c
5445 files changed
+1089914
No files matched your search
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "../src",
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
||||
+17
@@ -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
@@ -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
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
> @jimp/plugin-flip@1.5.0 build /Users/andrewlisowski/Documents/jimp/plugins/plugin-flip
|
||||
> tshy
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
> @jimp/plugin-flip@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/plugin-flip
|
||||
> eslint .
|
||||
|
||||
+5
@@ -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
@@ -0,0 +1,30 @@
|
||||
|
||||
|
||||
> @jimp/plugin-flip@1.1.2 test /Users/andrewlisowski/Documents/jimp/plugins/plugin-flip
|
||||
> vitest "--watch=false"
|
||||
|
||||
|
||||
[7m[1m[36m RUN [39m[22m[27m [36mv2.0.5[39m [90m/Users/andrewlisowski/Documents/jimp/plugins/plugin-flip[39m
|
||||
|
||||
[?25l [90m·[39m [2msrc/[22mindex[2m.test.ts[22m[2m (3)[22m
|
||||
[90m·[39m Flipping plugin[2m (3)[22m
|
||||
[90m·[39m can flip horizontally
|
||||
[90m·[39m can flip vertically
|
||||
[90m·[39m can flip both horizontally and vertically at once
|
||||
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (3)[22m
|
||||
[32m✓[39m Flipping plugin[2m (3)[22m
|
||||
[32m✓[39m can flip horizontally
|
||||
[32m✓[39m can flip vertically
|
||||
[32m✓[39m can flip both horizontally and vertically at once
|
||||
[?25l[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (3)[22m
|
||||
[32m✓[39m Flipping plugin[2m (3)[22m
|
||||
[32m✓[39m can flip horizontally
|
||||
[32m✓[39m can flip vertically
|
||||
[32m✓[39m can flip both horizontally and vertically at once
|
||||
|
||||
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
||||
[2m Tests [22m [1m[32m3 passed[39m[22m[90m (3)[39m
|
||||
[2m Start at [22m 01:33:33
|
||||
[2m Duration [22m 2.83s[2m (transform 997ms, setup 0ms, collect 1.36s, tests 5ms, environment 0ms, prepare 570ms)[22m
|
||||
|
||||
[?25h[?25h
|
||||
+52
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
+33
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import shared from "@jimp/config-eslint/base.js";
|
||||
export default [...shared];
|
||||
+67
@@ -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
@@ -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ᶠᶠ A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-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
@@ -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
@@ -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
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@jimp/config-typescript/base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import config from "@jimp/config-vitest/browser";
|
||||
|
||||
export default config;
|
||||
Reference in new issue
Block a user