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

> @jimp/plugin-cover@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/plugin-cover
> eslint .
+54
View File
@@ -0,0 +1,54 @@
> @jimp/plugin-cover@1.1.1 test:browser /Users/andrewlisowski/Documents/jimp/plugins/plugin-cover
> vitest --config vitest.config.browser.mjs "--watch=false" "--u"
 RUN  v1.4.0 /Users/andrewlisowski/Documents/jimp/plugins/plugin-cover
 Browser runner started at http://localhost:5174/
[?25l · All align combinations for cover (18)
· vertical contain aligned to LEFT TOP
· horizontal contain aligned to LEFT TOP
· vertical contain aligned to CENTER TOP
· horizontal contain aligned to CENTER TOP
· vertical contain aligned to RIGHT TOP
· horizontal contain aligned to RIGHT TOP
· vertical contain aligned to LEFT MIDDLE
· horizontal contain aligned to LEFT MIDDLE
· vertical contain aligned to CENTER MIDDLE
· horizontal contain aligned to CENTER MIDDLE
· vertical contain aligned to RIGHT MIDDLE
· horizontal contain aligned to RIGHT MIDDLE
· vertical contain aligned to LEFT BOTTOM
· horizontal contain aligned to LEFT BOTTOM
· vertical contain aligned to CENTER BOTTOM
· horizontal contain aligned to CENTER BOTTOM
· vertical contain aligned to RIGHT BOTTOM
· horizontal contain aligned to RIGHT BOTTOM
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l ✓ src/index.test.ts (18)
✓ All align combinations for cover (18)
✓ vertical contain aligned to LEFT TOP
✓ horizontal contain aligned to LEFT TOP
✓ vertical contain aligned to CENTER TOP
✓ horizontal contain aligned to CENTER TOP
✓ vertical contain aligned to RIGHT TOP
✓ horizontal contain aligned to RIGHT TOP
✓ vertical contain aligned to LEFT MIDDLE
✓ horizontal contain aligned to LEFT MIDDLE
✓ vertical contain aligned to CENTER MIDDLE
✓ horizontal contain aligned to CENTER MIDDLE
✓ vertical contain aligned to RIGHT MIDDLE
✓ horizontal contain aligned to RIGHT MIDDLE
✓ vertical contain aligned to LEFT BOTTOM
✓ horizontal contain aligned to LEFT BOTTOM
✓ vertical contain aligned to CENTER BOTTOM
✓ horizontal contain aligned to CENTER BOTTOM
✓ vertical contain aligned to RIGHT BOTTOM
✓ horizontal contain aligned to RIGHT BOTTOM
 Test Files  1 passed (1)
 Tests  18 passed (18)
 Start at  00:40:13
 Duration  2.83s (transform 0ms, setup 0ms, collect 93ms, tests 6ms, environment 0ms, prepare 0ms)
[?25h[?25h
+65
View File
@@ -0,0 +1,65 @@

> @jimp/plugin-cover@1.1.2 test /Users/andrewlisowski/Documents/jimp/plugins/plugin-cover
> vitest "--watch=false"
 RUN  v2.0.5 /Users/andrewlisowski/Documents/jimp/plugins/plugin-cover
[?25l · horizontal contain aligned to CENTER TOP
· vertical contain aligned to RIGHT TOP
· horizontal contain aligned to RIGHT TOP
· vertical contain aligned to LEFT MIDDLE
· horizontal contain aligned to LEFT MIDDLE
· vertical contain aligned to CENTER MIDDLE
· horizontal contain aligned to CENTER MIDDLE
· vertical contain aligned to RIGHT MIDDLE
· horizontal contain aligned to RIGHT MIDDLE
· vertical contain aligned to LEFT BOTTOM
· horizontal contain aligned to LEFT BOTTOM
· vertical contain aligned to CENTER BOTTOM
· horizontal contain aligned to CENTER BOTTOM
· vertical contain aligned to RIGHT BOTTOM
· horizontal contain aligned to RIGHT BOTTOM
[?25l[?25l ✓ horizontal contain aligned to CENTER TOP
✓ vertical contain aligned to RIGHT TOP
✓ horizontal contain aligned to RIGHT TOP
✓ vertical contain aligned to LEFT MIDDLE
✓ horizontal contain aligned to LEFT MIDDLE
✓ vertical contain aligned to CENTER MIDDLE
✓ horizontal contain aligned to CENTER MIDDLE
✓ vertical contain aligned to RIGHT MIDDLE
✓ horizontal contain aligned to RIGHT MIDDLE
✓ vertical contain aligned to LEFT BOTTOM
✓ horizontal contain aligned to LEFT BOTTOM
✓ vertical contain aligned to CENTER BOTTOM
✓ horizontal contain aligned to CENTER BOTTOM
✓ vertical contain aligned to RIGHT BOTTOM
✓ horizontal contain aligned to RIGHT BOTTOM
 ✓ src/index.test.ts (18)
✓ All align combinations for cover (18)
✓ vertical contain aligned to LEFT TOP
✓ horizontal contain aligned to LEFT TOP
✓ vertical contain aligned to CENTER TOP
✓ horizontal contain aligned to CENTER TOP
✓ vertical contain aligned to RIGHT TOP
✓ horizontal contain aligned to RIGHT TOP
✓ vertical contain aligned to LEFT MIDDLE
✓ horizontal contain aligned to LEFT MIDDLE
✓ vertical contain aligned to CENTER MIDDLE
✓ horizontal contain aligned to CENTER MIDDLE
✓ vertical contain aligned to RIGHT MIDDLE
✓ horizontal contain aligned to RIGHT MIDDLE
✓ vertical contain aligned to LEFT BOTTOM
✓ horizontal contain aligned to LEFT BOTTOM
✓ vertical contain aligned to CENTER BOTTOM
✓ horizontal contain aligned to CENTER BOTTOM
✓ vertical contain aligned to RIGHT BOTTOM
✓ horizontal contain aligned to RIGHT BOTTOM
 Test Files  1 passed (1)
 Tests  18 passed (18)
 Start at  01:34:10
 Duration  3.30s (transform 914ms, setup 0ms, collect 1.52s, tests 22ms, environment 0ms, prepare 791ms)
[?25h[?25h
+62
View File
@@ -0,0 +1,62 @@
# 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)
:tada: This release contains work from a new contributor! :tada:
Thank you, Ben McCann ([@benmccann](https://github.com/benmccann)), for all your work!
#### 🐛 Bug Fix
- remove hundreds of unused dependencies [#1302](https://github.com/jimp-dev/jimp/pull/1302) ([@benmccann](https://github.com/benmccann) [@hipstersmoothie](https://github.com/hipstersmoothie))
- 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: 2
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
- Ben McCann ([@benmccann](https://github.com/benmccann))
---
# 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))
#### 📝 Documentation
- remove outdated docs [#1301](https://github.com/jimp-dev/jimp/pull/1301) ([@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-cover</h1>
<p>Cover an image within a height and width.</p>
</div>
- [cover](http://jimp-dev.github.io/jimp/api/jimp/classes/jimp#cover)
+40
View File
@@ -0,0 +1,40 @@
import { JimpClass } from "@jimp/types";
import { ResizeStrategy } from "@jimp/plugin-resize";
import { z } from "zod";
declare const CoverOptionsSchema: z.ZodObject<{
/** the width to resize the image to */
w: z.ZodNumber;
/** the height to resize the image to */
h: z.ZodNumber;
/** A bitmask for horizontal and vertical alignment */
align: z.ZodOptional<z.ZodNumber>;
/** a scaling method (e.g. ResizeStrategy.BEZIER) */
mode: z.ZodOptional<z.ZodNativeEnum<typeof ResizeStrategy>>;
}, "strip", z.ZodTypeAny, {
w: number;
h: number;
align?: number | undefined;
mode?: ResizeStrategy | undefined;
}, {
w: number;
h: number;
align?: number | undefined;
mode?: ResizeStrategy | undefined;
}>;
export type CoverOptions = z.infer<typeof CoverOptionsSchema>;
export declare const methods: {
/**
* Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.cover(150, 100);
* ```
*/
cover<I extends JimpClass>(image: I, options: CoverOptions): 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,EAA4B,MAAM,qBAAqB,CAAC;AAE/E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,kBAAkB;IACtB,uCAAuC;;IAEvC,wCAAwC;;IAExC,sDAAsD;;IAEtD,oDAAoD;;;;;;;;;;;;EAEpD,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;OAUG;UACG,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,YAAY;CAyC3D,CAAC"}
+57
View File
@@ -0,0 +1,57 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.methods = void 0;
const core_1 = require("@jimp/core");
const plugin_resize_1 = require("@jimp/plugin-resize");
const plugin_crop_1 = require("@jimp/plugin-crop");
const zod_1 = require("zod");
const CoverOptionsSchema = zod_1.z.object({
/** the width to resize the image to */
w: zod_1.z.number(),
/** the height to resize the image to */
h: zod_1.z.number(),
/** A bitmask for horizontal and vertical alignment */
align: zod_1.z.number().optional(),
/** a scaling method (e.g. ResizeStrategy.BEZIER) */
mode: zod_1.z.nativeEnum(plugin_resize_1.ResizeStrategy).optional(),
});
exports.methods = {
/**
* Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.cover(150, 100);
* ```
*/
cover(image, options) {
const { w, h, align = core_1.HorizontalAlign.CENTER | core_1.VerticalAlign.MIDDLE, mode, } = CoverOptionsSchema.parse(options);
const hbits = align & ((1 << 3) - 1);
const vbits = align >> 3;
// check if more flags than one is in the bit sets
if (!((hbits !== 0 && !(hbits & (hbits - 1))) ||
(vbits !== 0 && !(vbits & (vbits - 1))))) {
throw new Error("only use one flag per alignment direction");
}
const alignH = hbits >> 1; // 0, 1, 2
const alignV = vbits >> 1; // 0, 1, 2
const f = w / h > image.bitmap.width / image.bitmap.height
? w / image.bitmap.width
: h / image.bitmap.height;
image = plugin_resize_1.methods.scale(image, {
f,
mode,
});
image = plugin_crop_1.methods.crop(image, {
x: ((image.bitmap.width - w) / 2) * alignH,
y: ((image.bitmap.height - h) / 2) * alignV,
w,
h,
});
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,qCAA4D;AAC5D,uDAA+E;AAC/E,mDAA2D;AAC3D,6BAAwB;AAExB,MAAM,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IAClC,uCAAuC;IACvC,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE;IACb,wCAAwC;IACxC,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE;IACb,sDAAsD;IACtD,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,oDAAoD;IACpD,IAAI,EAAE,OAAC,CAAC,UAAU,CAAC,8BAAc,CAAC,CAAC,QAAQ,EAAE;CAC9C,CAAC,CAAC;AAIU,QAAA,OAAO,GAAG;IACrB;;;;;;;;;;OAUG;IACH,KAAK,CAAsB,KAAQ,EAAE,OAAqB;QACxD,MAAM,EACJ,CAAC,EACD,CAAC,EACD,KAAK,GAAG,sBAAe,CAAC,MAAM,GAAG,oBAAa,CAAC,MAAM,EACrD,IAAI,GACL,GAAG,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtC,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,KAAK,IAAI,CAAC,CAAC;QAEzB,kDAAkD;QAClD,IACE,CAAC,CACC,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;YACvC,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CACxC,EACD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU;QACrC,MAAM,MAAM,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU;QAErC,MAAM,CAAC,GACL,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM;YAC9C,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK;YACxB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;QAE9B,KAAK,GAAG,uBAAa,CAAC,KAAK,CAAC,KAAK,EAAE;YACjC,CAAC;YACD,IAAI;SACL,CAAC,CAAC;QACH,KAAK,GAAG,qBAAW,CAAC,IAAI,CAAC,KAAK,EAAE;YAC9B,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM;YAC1C,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM;YAC3C,CAAC;YACD,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+40
View File
@@ -0,0 +1,40 @@
import { JimpClass } from "@jimp/types";
import { ResizeStrategy } from "@jimp/plugin-resize";
import { z } from "zod";
declare const CoverOptionsSchema: z.ZodObject<{
/** the width to resize the image to */
w: z.ZodNumber;
/** the height to resize the image to */
h: z.ZodNumber;
/** A bitmask for horizontal and vertical alignment */
align: z.ZodOptional<z.ZodNumber>;
/** a scaling method (e.g. ResizeStrategy.BEZIER) */
mode: z.ZodOptional<z.ZodNativeEnum<typeof ResizeStrategy>>;
}, "strip", z.ZodTypeAny, {
w: number;
h: number;
align?: number | undefined;
mode?: ResizeStrategy | undefined;
}, {
w: number;
h: number;
align?: number | undefined;
mode?: ResizeStrategy | undefined;
}>;
export type CoverOptions = z.infer<typeof CoverOptionsSchema>;
export declare const methods: {
/**
* Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.cover(150, 100);
* ```
*/
cover<I extends JimpClass>(image: I, options: CoverOptions): 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,EAA4B,MAAM,qBAAqB,CAAC;AAE/E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,kBAAkB;IACtB,uCAAuC;;IAEvC,wCAAwC;;IAExC,sDAAsD;;IAEtD,oDAAoD;;;;;;;;;;;;EAEpD,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;OAUG;UACG,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,YAAY;CAyC3D,CAAC"}
+54
View File
@@ -0,0 +1,54 @@
import { VerticalAlign, HorizontalAlign } from "@jimp/core";
import { ResizeStrategy, methods as resizeMethods } from "@jimp/plugin-resize";
import { methods as cropMethods } from "@jimp/plugin-crop";
import { z } from "zod";
const CoverOptionsSchema = z.object({
/** the width to resize the image to */
w: z.number(),
/** the height to resize the image to */
h: z.number(),
/** A bitmask for horizontal and vertical alignment */
align: z.number().optional(),
/** a scaling method (e.g. ResizeStrategy.BEZIER) */
mode: z.nativeEnum(ResizeStrategy).optional(),
});
export const methods = {
/**
* Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.cover(150, 100);
* ```
*/
cover(image, options) {
const { w, h, align = HorizontalAlign.CENTER | VerticalAlign.MIDDLE, mode, } = CoverOptionsSchema.parse(options);
const hbits = align & ((1 << 3) - 1);
const vbits = align >> 3;
// check if more flags than one is in the bit sets
if (!((hbits !== 0 && !(hbits & (hbits - 1))) ||
(vbits !== 0 && !(vbits & (vbits - 1))))) {
throw new Error("only use one flag per alignment direction");
}
const alignH = hbits >> 1; // 0, 1, 2
const alignV = vbits >> 1; // 0, 1, 2
const f = w / h > image.bitmap.width / image.bitmap.height
? w / image.bitmap.width
: h / image.bitmap.height;
image = resizeMethods.scale(image, {
f,
mode,
});
image = cropMethods.crop(image, {
x: ((image.bitmap.width - w) / 2) * alignH,
y: ((image.bitmap.height - h) / 2) * alignV,
w,
h,
});
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,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,uCAAuC;IACvC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;IACb,wCAAwC;IACxC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;IACb,sDAAsD;IACtD,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,oDAAoD;IACpD,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE;CAC9C,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB;;;;;;;;;;OAUG;IACH,KAAK,CAAsB,KAAQ,EAAE,OAAqB;QACxD,MAAM,EACJ,CAAC,EACD,CAAC,EACD,KAAK,GAAG,eAAe,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,EACrD,IAAI,GACL,GAAG,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtC,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,KAAK,IAAI,CAAC,CAAC;QAEzB,kDAAkD;QAClD,IACE,CAAC,CACC,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;YACvC,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CACxC,EACD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU;QACrC,MAAM,MAAM,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU;QAErC,MAAM,CAAC,GACL,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM;YAC9C,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK;YACxB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;QAE9B,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE;YACjC,CAAC;YACD,IAAI;SACL,CAAC,CAAC;QACH,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE;YAC9B,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM;YAC1C,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM;YAC3C,CAAC;YACD,CAAC;SACF,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];
+68
View File
@@ -0,0 +1,68 @@
{
"name": "@jimp/plugin-cover",
"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/core": "1.6.0",
"@jimp/plugin-crop": "1.6.0",
"@jimp/plugin-resize": "1.6.0",
"@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/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"
}
+289
View File
@@ -0,0 +1,289 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`All align combinations for cover > horizontal contain aligned to CENTER BOTTOM 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > horizontal contain aligned to CENTER MIDDLE 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > horizontal contain aligned to CENTER TOP 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > horizontal contain aligned to LEFT BOTTOM 1`] = `
Visualization:
▴▴▴▸
▴▴▴▸
▾▾▾◆
▾▾▾◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > horizontal contain aligned to LEFT MIDDLE 1`] = `
Visualization:
▴▴▴▸
▴▴▴▸
▾▾▾◆
▾▾▾◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > horizontal contain aligned to LEFT TOP 1`] = `
Visualization:
▴▴▴▸
▴▴▴▸
▾▾▾◆
▾▾▾◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > horizontal contain aligned to RIGHT BOTTOM 1`] = `
Visualization:
▴▸▸▸
▴▸▸▸
▾◆◆◆
▾◆◆◆
Data:
FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > horizontal contain aligned to RIGHT MIDDLE 1`] = `
Visualization:
▴▸▸▸
▴▸▸▸
▾◆◆◆
▾◆◆◆
Data:
FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > horizontal contain aligned to RIGHT TOP 1`] = `
Visualization:
▴▸▸▸
▴▸▸▸
▾◆◆◆
▾◆◆◆
Data:
FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > vertical contain aligned to CENTER BOTTOM 1`] = `
Visualization:
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > vertical contain aligned to CENTER MIDDLE 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > vertical contain aligned to CENTER TOP 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > vertical contain aligned to LEFT BOTTOM 1`] = `
Visualization:
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > vertical contain aligned to LEFT MIDDLE 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > vertical contain aligned to LEFT TOP 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > vertical contain aligned to RIGHT BOTTOM 1`] = `
Visualization:
▴▴▸▸
▾▾◆◆
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > vertical contain aligned to RIGHT MIDDLE 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▾▾◆◆
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
exports[`All align combinations for cover > vertical contain aligned to RIGHT TOP 1`] = `
Visualization:
▴▴▸▸
▴▴▸▸
▴▴▸▸
▾▾◆◆
Data:
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
FF-00-00ᶠᶠ FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-FF-00ᶠᶠ
00-00-FFᶠᶠ 00-00-FFᶠᶠ FF-FF-00ᶠᶠ FF-FF-00ᶠᶠ
`;
+74
View File
@@ -0,0 +1,74 @@
import { expect, test, describe } from "vitest";
import { HorizontalAlign, VerticalAlign, createJimp } from "@jimp/core";
import { makeTestImage } from "@jimp/test-utils";
import { methods } from "./index.js";
const jimp = createJimp({ plugins: [methods] });
describe("All align combinations for cover", () => {
const vertical = jimp.fromBitmap(
makeTestImage(
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
),
);
const horizontal = jimp.fromBitmap(
makeTestImage(
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▾▾▾▾▾▾◆◆◆◆◆◆",
"▾▾▾▾▾▾◆◆◆◆◆◆",
"▾▾▾▾▾▾◆◆◆◆◆◆",
"▾▾▾▾▾▾◆◆◆◆◆◆",
),
);
const tests: Array<
[keyof typeof HorizontalAlign, keyof typeof VerticalAlign]
> = [
["LEFT", "TOP"],
["CENTER", "TOP"],
["RIGHT", "TOP"],
["LEFT", "MIDDLE"],
["CENTER", "MIDDLE"],
["RIGHT", "MIDDLE"],
["LEFT", "BOTTOM"],
["CENTER", "BOTTOM"],
["RIGHT", "BOTTOM"],
];
tests.forEach(([horizontalAlign, verticalAlign]) => {
const align = horizontalAlign + " " + verticalAlign;
const alignValue =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(HorizontalAlign as any)[horizontalAlign] |
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(VerticalAlign as any)[verticalAlign];
test("vertical contain aligned to " + align, () => {
expect(
vertical.clone().cover({ w: 4, h: 4, align: alignValue }),
).toMatchSnapshot();
});
test("horizontal contain aligned to " + align, () => {
expect(
horizontal.clone().cover({ w: 4, h: 4, align: alignValue }),
).toMatchSnapshot();
});
});
});
+73
View File
@@ -0,0 +1,73 @@
import { JimpClass } from "@jimp/types";
import { VerticalAlign, HorizontalAlign } from "@jimp/core";
import { ResizeStrategy, methods as resizeMethods } from "@jimp/plugin-resize";
import { methods as cropMethods } from "@jimp/plugin-crop";
import { z } from "zod";
const CoverOptionsSchema = z.object({
/** the width to resize the image to */
w: z.number(),
/** the height to resize the image to */
h: z.number(),
/** A bitmask for horizontal and vertical alignment */
align: z.number().optional(),
/** a scaling method (e.g. ResizeStrategy.BEZIER) */
mode: z.nativeEnum(ResizeStrategy).optional(),
});
export type CoverOptions = z.infer<typeof CoverOptionsSchema>;
export const methods = {
/**
* Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.cover(150, 100);
* ```
*/
cover<I extends JimpClass>(image: I, options: CoverOptions) {
const {
w,
h,
align = HorizontalAlign.CENTER | VerticalAlign.MIDDLE,
mode,
} = CoverOptionsSchema.parse(options);
const hbits = align & ((1 << 3) - 1);
const vbits = align >> 3;
// check if more flags than one is in the bit sets
if (
!(
(hbits !== 0 && !(hbits & (hbits - 1))) ||
(vbits !== 0 && !(vbits & (vbits - 1)))
)
) {
throw new Error("only use one flag per alignment direction");
}
const alignH = hbits >> 1; // 0, 1, 2
const alignV = vbits >> 1; // 0, 1, 2
const f =
w / h > image.bitmap.width / image.bitmap.height
? w / image.bitmap.width
: h / image.bitmap.height;
image = resizeMethods.scale(image, {
f,
mode,
});
image = cropMethods.crop(image, {
x: ((image.bitmap.width - w) / 2) * alignH,
y: ((image.bitmap.height - h) / 2) * alignV,
w,
h,
});
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;