chore: add jimp dependency, icon padding script, and update configuration
This commit is contained in:
+85
@@ -0,0 +1,85 @@
|
||||
# v0.22.1 (Mon Feb 06 2023)
|
||||
|
||||
#### 🏠 Internal
|
||||
|
||||
- rename master to main [#1169](https://github.com/jimp-dev/jimp/pull/1169) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v0.22.0 (Mon Feb 06 2023)
|
||||
|
||||
#### 🏠 Internal
|
||||
|
||||
- switch from should to expect [#1163](https://github.com/jimp-dev/jimp/pull/1163) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
- Change test matching strategy to include all test files [#1161](https://github.com/jimp-dev/jimp/pull/1161) ([@danielholmes](https://github.com/danielholmes))
|
||||
|
||||
#### Authors: 2
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
- Daniel Holmes ([@danielholmes](https://github.com/danielholmes))
|
||||
|
||||
---
|
||||
|
||||
# v0.21.0 (Sun Feb 05 2023)
|
||||
|
||||
### Release Notes
|
||||
|
||||
#### Babel Refactor ([#1149](https://github.com/jimp-dev/jimp/pull/1149))
|
||||
|
||||
Marking this as a "breaking release" because it might change what deps need to be installed.
|
||||
|
||||
All modules should be exported as valid cjs and esm
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
#### 💥 Breaking Change
|
||||
|
||||
- Babel Refactor [#1149](https://github.com/jimp-dev/jimp/pull/1149) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v0.16.3 (Sat Feb 04 2023)
|
||||
|
||||
#### ⚠️ Pushed to `main`
|
||||
|
||||
- upgrade prettier ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v0.11.0 (Fri May 15 2020)
|
||||
|
||||
#### 🚀 Enhancement
|
||||
|
||||
- Removed Core-JS as a dependency. [#882](https://github.com/oliver-moran/jimp/pull/882) ([@EricRabil](https://github.com/EricRabil))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Eric Rabil ([@EricRabil](https://github.com/EricRabil))
|
||||
|
||||
---
|
||||
|
||||
# v0.9.3 (Tue Nov 26 2019)
|
||||
|
||||
#### 🐛 Bug Fix
|
||||
|
||||
- `@jimp/cli`, `@jimp/core`, `@jimp/custom`, `jimp`, `@jimp/plugin-blit`, `@jimp/plugin-blur`, `@jimp/plugin-circle`, `@jimp/plugin-color`, `@jimp/plugin-contain`, `@jimp/plugin-cover`, `@jimp/plugin-crop`, `@jimp/plugin-displace`, `@jimp/plugin-dither`, `@jimp/plugin-fisheye`, `@jimp/plugin-flip`, `@jimp/plugin-gaussian`, `@jimp/plugin-invert`, `@jimp/plugin-mask`, `@jimp/plugin-normalize`, `@jimp/plugin-print`, `@jimp/plugin-resize`, `@jimp/plugin-rotate`, `@jimp/plugin-scale`, `@jimp/plugin-shadow`, `@jimp/plugin-threshold`, `@jimp/plugins`, `@jimp/test-utils`, `@jimp/bmp`, `@jimp/gif`, `@jimp/jpeg`, `@jimp/png`, `@jimp/tiff`, `@jimp/types`, `@jimp/utils`
|
||||
- Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 2
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))
|
||||
+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.
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<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>
|
||||
</div>
|
||||
|
||||
Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.
|
||||
|
||||
## Usage
|
||||
|
||||
- @param {number} w the width to resize the image to
|
||||
- @param {number} h the height to resize the image to
|
||||
- @param {number} alignBits (optional) A bitmask for horizontal and vertical alignment
|
||||
- @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)
|
||||
- @param {function(Error, Jimp)} cb (optional) a callback for when complete
|
||||
|
||||
```js
|
||||
import jimp from "jimp";
|
||||
|
||||
async function main() {
|
||||
const image = await jimp.read("test/image.png");
|
||||
|
||||
image.cover(150, 100);
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
|
||||
### Align modes
|
||||
|
||||
The following constants can be passed to `image.cover`:
|
||||
|
||||
```js
|
||||
Jimp.HORIZONTAL_ALIGN_LEFT;
|
||||
Jimp.HORIZONTAL_ALIGN_CENTER;
|
||||
Jimp.HORIZONTAL_ALIGN_RIGHT;
|
||||
|
||||
Jimp.VERTICAL_ALIGN_TOP;
|
||||
Jimp.VERTICAL_ALIGN_MIDDLE;
|
||||
Jimp.VERTICAL_ALIGN_BOTTOM;
|
||||
```
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
image.cover(250, 250, Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_TOP);
|
||||
image.cover(250, 250, Jimp.HORIZONTAL_ALIGN_RIGHT | Jimp.VERTICAL_ALIGN_BOTTOM);
|
||||
```
|
||||
|
||||
Default align mode for `image.cover` is:
|
||||
|
||||
```js
|
||||
Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE;
|
||||
```
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import { isNodePattern, throwError } from "@jimp/utils";
|
||||
|
||||
/**
|
||||
* Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.
|
||||
* @param {number} w the width to resize the image to
|
||||
* @param {number} h the height to resize the image to
|
||||
* @param {number} alignBits (optional) A bitmask for horizontal and vertical alignment
|
||||
* @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)
|
||||
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
export default (() => ({
|
||||
cover(w, h, alignBits, mode, cb) {
|
||||
if (typeof w !== "number" || typeof h !== "number") {
|
||||
return throwError.call(this, "w and h must be numbers", cb);
|
||||
}
|
||||
if (alignBits && typeof alignBits === "function" && typeof cb === "undefined") {
|
||||
cb = alignBits;
|
||||
alignBits = null;
|
||||
mode = null;
|
||||
} else if (typeof mode === "function" && typeof cb === "undefined") {
|
||||
cb = mode;
|
||||
mode = null;
|
||||
}
|
||||
alignBits = alignBits || this.constructor.HORIZONTAL_ALIGN_CENTER | this.constructor.VERTICAL_ALIGN_MIDDLE;
|
||||
const hbits = alignBits & (1 << 3) - 1;
|
||||
const vbits = alignBits >> 3;
|
||||
|
||||
// check if more flags than one is in the bit sets
|
||||
if (!(hbits !== 0 && !(hbits & hbits - 1) || vbits !== 0 && !(vbits & vbits - 1))) return throwError.call(this, "only use one flag per alignment direction", cb);
|
||||
const alignH = hbits >> 1; // 0, 1, 2
|
||||
const alignV = vbits >> 1; // 0, 1, 2
|
||||
|
||||
const f = w / h > this.bitmap.width / this.bitmap.height ? w / this.bitmap.width : h / this.bitmap.height;
|
||||
this.scale(f, mode);
|
||||
this.crop((this.bitmap.width - w) / 2 * alignH, (this.bitmap.height - h) / 2 * alignV, w, h);
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","names":["isNodePattern","throwError","cover","w","h","alignBits","mode","cb","call","constructor","HORIZONTAL_ALIGN_CENTER","VERTICAL_ALIGN_MIDDLE","hbits","vbits","alignH","alignV","f","bitmap","width","height","scale","crop"],"sources":["../src/index.js"],"sourcesContent":["import { isNodePattern, throwError } from \"@jimp/utils\";\n\n/**\n * Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.\n * @param {number} w the width to resize the image to\n * @param {number} h the height to resize the image to\n * @param {number} alignBits (optional) A bitmask for horizontal and vertical alignment\n * @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\nexport default () => ({\n cover(w, h, alignBits, mode, cb) {\n if (typeof w !== \"number\" || typeof h !== \"number\") {\n return throwError.call(this, \"w and h must be numbers\", cb);\n }\n\n if (\n alignBits &&\n typeof alignBits === \"function\" &&\n typeof cb === \"undefined\"\n ) {\n cb = alignBits;\n alignBits = null;\n mode = null;\n } else if (typeof mode === \"function\" && typeof cb === \"undefined\") {\n cb = mode;\n mode = null;\n }\n\n alignBits =\n alignBits ||\n this.constructor.HORIZONTAL_ALIGN_CENTER |\n this.constructor.VERTICAL_ALIGN_MIDDLE;\n const hbits = alignBits & ((1 << 3) - 1);\n const vbits = alignBits >> 3;\n\n // check if more flags than one is in the bit sets\n if (\n !(\n (hbits !== 0 && !(hbits & (hbits - 1))) ||\n (vbits !== 0 && !(vbits & (vbits - 1)))\n )\n )\n return throwError.call(\n this,\n \"only use one flag per alignment direction\",\n cb\n );\n\n const alignH = hbits >> 1; // 0, 1, 2\n const alignV = vbits >> 1; // 0, 1, 2\n\n const f =\n w / h > this.bitmap.width / this.bitmap.height\n ? w / this.bitmap.width\n : h / this.bitmap.height;\n this.scale(f, mode);\n this.crop(\n ((this.bitmap.width - w) / 2) * alignH,\n ((this.bitmap.height - h) / 2) * alignV,\n w,\n h\n );\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n },\n});\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,aAAa;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAe,OAAO;EACpBC,KAAK,CAACC,CAAC,EAAEC,CAAC,EAAEC,SAAS,EAAEC,IAAI,EAAEC,EAAE,EAAE;IAC/B,IAAI,OAAOJ,CAAC,KAAK,QAAQ,IAAI,OAAOC,CAAC,KAAK,QAAQ,EAAE;MAClD,OAAOH,UAAU,CAACO,IAAI,CAAC,IAAI,EAAE,yBAAyB,EAAED,EAAE,CAAC;IAC7D;IAEA,IACEF,SAAS,IACT,OAAOA,SAAS,KAAK,UAAU,IAC/B,OAAOE,EAAE,KAAK,WAAW,EACzB;MACAA,EAAE,GAAGF,SAAS;MACdA,SAAS,GAAG,IAAI;MAChBC,IAAI,GAAG,IAAI;IACb,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,UAAU,IAAI,OAAOC,EAAE,KAAK,WAAW,EAAE;MAClEA,EAAE,GAAGD,IAAI;MACTA,IAAI,GAAG,IAAI;IACb;IAEAD,SAAS,GACPA,SAAS,IACT,IAAI,CAACI,WAAW,CAACC,uBAAuB,GACtC,IAAI,CAACD,WAAW,CAACE,qBAAqB;IAC1C,MAAMC,KAAK,GAAGP,SAAS,GAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAE;IACxC,MAAMQ,KAAK,GAAGR,SAAS,IAAI,CAAC;;IAE5B;IACA,IACE,EACGO,KAAK,KAAK,CAAC,IAAI,EAAEA,KAAK,GAAIA,KAAK,GAAG,CAAE,CAAC,IACrCC,KAAK,KAAK,CAAC,IAAI,EAAEA,KAAK,GAAIA,KAAK,GAAG,CAAE,CAAE,CACxC,EAED,OAAOZ,UAAU,CAACO,IAAI,CACpB,IAAI,EACJ,2CAA2C,EAC3CD,EAAE,CACH;IAEH,MAAMO,MAAM,GAAGF,KAAK,IAAI,CAAC,CAAC,CAAC;IAC3B,MAAMG,MAAM,GAAGF,KAAK,IAAI,CAAC,CAAC,CAAC;;IAE3B,MAAMG,CAAC,GACLb,CAAC,GAAGC,CAAC,GAAG,IAAI,CAACa,MAAM,CAACC,KAAK,GAAG,IAAI,CAACD,MAAM,CAACE,MAAM,GAC1ChB,CAAC,GAAG,IAAI,CAACc,MAAM,CAACC,KAAK,GACrBd,CAAC,GAAG,IAAI,CAACa,MAAM,CAACE,MAAM;IAC5B,IAAI,CAACC,KAAK,CAACJ,CAAC,EAAEV,IAAI,CAAC;IACnB,IAAI,CAACe,IAAI,CACN,CAAC,IAAI,CAACJ,MAAM,CAACC,KAAK,GAAGf,CAAC,IAAI,CAAC,GAAIW,MAAM,EACrC,CAAC,IAAI,CAACG,MAAM,CAACE,MAAM,GAAGf,CAAC,IAAI,CAAC,GAAIW,MAAM,EACvCZ,CAAC,EACDC,CAAC,CACF;IAED,IAAIJ,aAAa,CAACO,EAAE,CAAC,EAAE;MACrBA,EAAE,CAACC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC3B;IAEA,OAAO,IAAI;EACb;AACF,CAAC,CAAC"}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { ImageCallback } from "@jimp/core";
|
||||
|
||||
interface Cover {
|
||||
cover(w: number, h: number, cb?: ImageCallback<this>): this;
|
||||
cover(
|
||||
w: number,
|
||||
h: number,
|
||||
alignBits?: number,
|
||||
cb?: ImageCallback<this>
|
||||
): this;
|
||||
cover(
|
||||
w: number,
|
||||
h: number,
|
||||
alignBits?: number,
|
||||
mode?: string,
|
||||
cb?: ImageCallback<this>
|
||||
): this;
|
||||
}
|
||||
|
||||
export default function (): Cover;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "@jimp/plugin-cover",
|
||||
"version": "0.22.12",
|
||||
"description": "cover an image.",
|
||||
"main": "dist/index.js",
|
||||
"module": "es/index.js",
|
||||
"repository": "jimp-dev/jimp",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"test": "cross-env BABEL_ENV=test mocha --require @babel/register --recursive test --extension js",
|
||||
"test:watch": "npm run test -- --reporter min --watch",
|
||||
"test:coverage": "nyc npm run test",
|
||||
"build": "npm run build:node:production && npm run build:module",
|
||||
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
|
||||
"build:debug": "npm run build:node:debug",
|
||||
"build:module": "cross-env BABEL_ENV=module babel src -d es --source-maps --config-file ../../babel.config.js",
|
||||
"build:node": "babel src -d dist --source-maps --config-file ../../babel.config.js",
|
||||
"build:node:debug": "cross-env BABEL_ENV=development npm run build:node",
|
||||
"build:node:production": "cross-env BABEL_ENV=production npm run build:node"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jimp/utils": "^0.22.12"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@jimp/custom": ">=0.3.5",
|
||||
"@jimp/plugin-crop": ">=0.3.5",
|
||||
"@jimp/plugin-resize": ">=0.3.5",
|
||||
"@jimp/plugin-scale": ">=0.3.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jimp/custom": "^0.22.12",
|
||||
"@jimp/plugin-crop": "^0.22.12",
|
||||
"@jimp/plugin-resize": "^0.22.12",
|
||||
"@jimp/plugin-scale": "^0.22.12",
|
||||
"@jimp/test-utils": "^0.22.12"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "a4a8d6364bbf97629749e196f3b0a4c94c9a7abc"
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
import { isNodePattern, throwError } from "@jimp/utils";
|
||||
|
||||
/**
|
||||
* Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.
|
||||
* @param {number} w the width to resize the image to
|
||||
* @param {number} h the height to resize the image to
|
||||
* @param {number} alignBits (optional) A bitmask for horizontal and vertical alignment
|
||||
* @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)
|
||||
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
export default () => ({
|
||||
cover(w, h, alignBits, mode, cb) {
|
||||
if (typeof w !== "number" || typeof h !== "number") {
|
||||
return throwError.call(this, "w and h must be numbers", cb);
|
||||
}
|
||||
|
||||
if (
|
||||
alignBits &&
|
||||
typeof alignBits === "function" &&
|
||||
typeof cb === "undefined"
|
||||
) {
|
||||
cb = alignBits;
|
||||
alignBits = null;
|
||||
mode = null;
|
||||
} else if (typeof mode === "function" && typeof cb === "undefined") {
|
||||
cb = mode;
|
||||
mode = null;
|
||||
}
|
||||
|
||||
alignBits =
|
||||
alignBits ||
|
||||
this.constructor.HORIZONTAL_ALIGN_CENTER |
|
||||
this.constructor.VERTICAL_ALIGN_MIDDLE;
|
||||
const hbits = alignBits & ((1 << 3) - 1);
|
||||
const vbits = alignBits >> 3;
|
||||
|
||||
// check if more flags than one is in the bit sets
|
||||
if (
|
||||
!(
|
||||
(hbits !== 0 && !(hbits & (hbits - 1))) ||
|
||||
(vbits !== 0 && !(vbits & (vbits - 1)))
|
||||
)
|
||||
)
|
||||
return throwError.call(
|
||||
this,
|
||||
"only use one flag per alignment direction",
|
||||
cb
|
||||
);
|
||||
|
||||
const alignH = hbits >> 1; // 0, 1, 2
|
||||
const alignV = vbits >> 1; // 0, 1, 2
|
||||
|
||||
const f =
|
||||
w / h > this.bitmap.width / this.bitmap.height
|
||||
? w / this.bitmap.width
|
||||
: h / this.bitmap.height;
|
||||
this.scale(f, mode);
|
||||
this.crop(
|
||||
((this.bitmap.width - w) / 2) * alignH,
|
||||
((this.bitmap.height - h) / 2) * alignV,
|
||||
w,
|
||||
h
|
||||
);
|
||||
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
});
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
import { Jimp, mkJGD, hasOwnProp } from "@jimp/test-utils";
|
||||
import configure from "@jimp/custom";
|
||||
import crop from "@jimp/plugin-crop";
|
||||
import scale from "@jimp/plugin-scale";
|
||||
import resize from "@jimp/plugin-resize";
|
||||
|
||||
import cover from "../src";
|
||||
import { expectToBeJGD } from "@jimp/test-utils/src";
|
||||
|
||||
const jimp = configure({ plugins: [resize, scale, crop, cover] }, Jimp);
|
||||
|
||||
describe("All align combinations for cover", () => {
|
||||
const verticalJGD = mkJGD(
|
||||
"▴▴▴▴▸▸▸▸",
|
||||
"▴▴▴▴▸▸▸▸",
|
||||
"▴▴▴▴▸▸▸▸",
|
||||
"▴▴▴▴▸▸▸▸",
|
||||
"▴▴▴▴▸▸▸▸",
|
||||
"▴▴▴▴▸▸▸▸",
|
||||
"▾▾▾▾◆◆◆◆",
|
||||
"▾▾▾▾◆◆◆◆",
|
||||
"▾▾▾▾◆◆◆◆",
|
||||
"▾▾▾▾◆◆◆◆",
|
||||
"▾▾▾▾◆◆◆◆",
|
||||
"▾▾▾▾◆◆◆◆"
|
||||
);
|
||||
|
||||
const horizontalJGD = mkJGD(
|
||||
"▴▴▴▴▴▴▸▸▸▸▸▸",
|
||||
"▴▴▴▴▴▴▸▸▸▸▸▸",
|
||||
"▴▴▴▴▴▴▸▸▸▸▸▸",
|
||||
"▴▴▴▴▴▴▸▸▸▸▸▸",
|
||||
"▾▾▾▾▾▾◆◆◆◆◆◆",
|
||||
"▾▾▾▾▾▾◆◆◆◆◆◆",
|
||||
"▾▾▾▾▾▾◆◆◆◆◆◆",
|
||||
"▾▾▾▾▾▾◆◆◆◆◆◆"
|
||||
);
|
||||
|
||||
let vertical;
|
||||
let horizontal; // stores the Jimp instances of the JGD images above.
|
||||
|
||||
before((done) => {
|
||||
const img1 = jimp.read(verticalJGD);
|
||||
const img2 = jimp.read(horizontalJGD);
|
||||
Promise.all([img1, img2])
|
||||
.then((images) => {
|
||||
vertical = images[0];
|
||||
horizontal = images[1];
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
const tests = {}; // Stores the expected result for each alignment combination.
|
||||
tests["LEFT TOP"] = {
|
||||
cover: {
|
||||
verti: mkJGD("▴▴▸▸", "▴▴▸▸", "▴▴▸▸", "▾▾◆◆"),
|
||||
horiz: mkJGD("▴▴▴▸", "▴▴▴▸", "▾▾▾◆", "▾▾▾◆"),
|
||||
},
|
||||
};
|
||||
tests["CENTER TOP"] = {
|
||||
cover: {
|
||||
verti: mkJGD("▴▴▸▸", "▴▴▸▸", "▴▴▸▸", "▾▾◆◆"),
|
||||
horiz: mkJGD("▴▴▸▸", "▴▴▸▸", "▾▾◆◆", "▾▾◆◆"),
|
||||
},
|
||||
};
|
||||
tests["RIGHT TOP"] = {
|
||||
cover: {
|
||||
verti: mkJGD("▴▴▸▸", "▴▴▸▸", "▴▴▸▸", "▾▾◆◆"),
|
||||
horiz: mkJGD("▴▸▸▸", "▴▸▸▸", "▾◆◆◆", "▾◆◆◆"),
|
||||
},
|
||||
};
|
||||
|
||||
tests["LEFT MIDDLE"] = {
|
||||
cover: {
|
||||
verti: mkJGD("▴▴▸▸", "▴▴▸▸", "▾▾◆◆", "▾▾◆◆"),
|
||||
horiz: mkJGD("▴▴▴▸", "▴▴▴▸", "▾▾▾◆", "▾▾▾◆"),
|
||||
},
|
||||
};
|
||||
tests["CENTER MIDDLE"] = {
|
||||
cover: {
|
||||
verti: mkJGD("▴▴▸▸", "▴▴▸▸", "▾▾◆◆", "▾▾◆◆"),
|
||||
horiz: mkJGD("▴▴▸▸", "▴▴▸▸", "▾▾◆◆", "▾▾◆◆"),
|
||||
},
|
||||
};
|
||||
tests["RIGHT MIDDLE"] = {
|
||||
cover: {
|
||||
verti: mkJGD("▴▴▸▸", "▴▴▸▸", "▾▾◆◆", "▾▾◆◆"),
|
||||
horiz: mkJGD("▴▸▸▸", "▴▸▸▸", "▾◆◆◆", "▾◆◆◆"),
|
||||
},
|
||||
};
|
||||
|
||||
tests["LEFT BOTTOM"] = {
|
||||
cover: {
|
||||
verti: mkJGD("▴▴▸▸", "▾▾◆◆", "▾▾◆◆", "▾▾◆◆"),
|
||||
horiz: mkJGD("▴▴▴▸", "▴▴▴▸", "▾▾▾◆", "▾▾▾◆"),
|
||||
},
|
||||
};
|
||||
tests["CENTER BOTTOM"] = {
|
||||
cover: {
|
||||
verti: mkJGD("▴▴▸▸", "▾▾◆◆", "▾▾◆◆", "▾▾◆◆"),
|
||||
horiz: mkJGD("▴▴▸▸", "▴▴▸▸", "▾▾◆◆", "▾▾◆◆"),
|
||||
},
|
||||
};
|
||||
tests["RIGHT BOTTOM"] = {
|
||||
cover: {
|
||||
verti: mkJGD("▴▴▸▸", "▾▾◆◆", "▾▾◆◆", "▾▾◆◆"),
|
||||
horiz: mkJGD("▴▸▸▸", "▴▸▸▸", "▾◆◆◆", "▾◆◆◆"),
|
||||
},
|
||||
};
|
||||
|
||||
function runAlignTest(align) {
|
||||
const jgdCoverV = tests[align].cover.verti;
|
||||
const jgdCoverH = tests[align].cover.horiz;
|
||||
let a = align.split(" ");
|
||||
a = Jimp["HORIZONTAL_ALIGN_" + a[0]] | Jimp["VERTICAL_ALIGN_" + a[1]];
|
||||
it("cover aligned to " + align, () => {
|
||||
expectToBeJGD(vertical.clone().cover(4, 4, a).getJGDSync(), jgdCoverV);
|
||||
expectToBeJGD(horizontal.clone().cover(4, 4, a).getJGDSync(), jgdCoverH);
|
||||
});
|
||||
}
|
||||
|
||||
for (const align in tests) if (hasOwnProp(tests, align)) runAlignTest(align);
|
||||
});
|
||||
Reference in New Issue
Block a user