chore: add jimp dependency, icon padding script, and update configuration

This commit is contained in:
2026-05-31 14:04:37 +02:00
parent 30f81045ac
commit 7cd17307ba
1126 changed files with 166400 additions and 2 deletions
+133
View File
@@ -0,0 +1,133 @@
# v0.22.8 (Thu May 11 2023)
#### 🚀 Enhancement
- Fix: rotate resize param on multiples of 90 [#1229](https://github.com/jimp-dev/jimp/pull/1229) ([@sjoerd108](https://github.com/sjoerd108))
#### Authors: 1
- Sjoerd ([@sjoerd108](https://github.com/sjoerd108))
---
# v0.22.7 (Sat Feb 25 2023)
:tada: This release contains work from a new contributor! :tada:
Thank you, MD KHAIRUL ISLAM ([@black-turtle](https://github.com/black-turtle)), for all your work!
### Release Notes
#### use matrix rotate, if rotate angle is multiple of 90 degrees ([#1209](https://github.com/jimp-dev/jimp/pull/1209))
Fixes a bug where rotating by 90 degrees introduced extra pixels
---
#### 🐛 Bug Fix
- use matrix rotate, if rotate angle is multiple of 90 degrees [#1209](https://github.com/jimp-dev/jimp/pull/1209) ([@black-turtle](https://github.com/black-turtle))
#### Authors: 1
- MD KHAIRUL ISLAM ([@black-turtle](https://github.com/black-turtle))
---
# 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
![CleanShot 2023-02-04 at 18 19 27](https://user-images.githubusercontent.com/1192452/216798157-664cc430-7846-432d-84cf-26e8d8ba9e10.png)
---
#### 💥 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.17.6 (Sat Feb 04 2023)
#### 🐛 Bug Fix
- fix documentation about rotation direction. [#1062](https://github.com/jimp-dev/jimp/pull/1062) ([@fabb](https://github.com/fabb))
#### Authors: 1
- [@fabb](https://github.com/fabb)
---
# 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
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.
+26
View File
@@ -0,0 +1,26 @@
<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-rotate</h1>
<p>Rotate an image.</p>
</div>
Rotates the image counter-clockwise by a number of degrees. By default the width and height of the image will be resized appropriately.
## Usage
- @param {number} deg the number of degrees to rotate the image by, counter-clockwise
- @param {string|boolean} mode (optional) resize mode or a boolean, if false then the width and height of the image will not be changed
- @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.rotate(90);
}
main();
```
+196
View File
@@ -0,0 +1,196 @@
import { isNodePattern, throwError } from "@jimp/utils";
/**
* Rotates an image counter-clockwise by multiple of 90 degrees. NB: 'this' must be a Jimp object.
*
* This function is based on matrix rotation. Check this to get an initial idea how it works: https://stackoverflow.com/a/8664879/10561909
*
* @param {number} deg the number of degrees to rotate the image by, it should be a multiple of 90
*/
function matrixRotate(deg) {
if (Math.abs(deg) % 90 !== 0) {
throw new Error("Unsupported matrix rotation degree");
}
deg %= 360;
if (Math.abs(deg) === 0) {
// no rotation for 0, 360, -360, 720, -720, ...
return;
}
const w = this.bitmap.width;
const h = this.bitmap.height;
// decide which rotation angle to use
let angle;
switch (deg) {
// 90 degree & -270 degree are same
case 90:
case -270:
angle = 90;
break;
case 180:
case -180:
angle = 180;
break;
case 270:
case -90:
angle = -90;
break;
default:
throw new Error("Unsupported matrix rotation degree");
}
// After this switch block, angle will be 90, 180 or -90
// calculate the new width and height
const nW = angle === 180 ? w : h;
const nH = angle === 180 ? h : w;
const dstBuffer = Buffer.alloc(this.bitmap.data.length);
// function to translate the x, y coordinate to the index of the pixel in the buffer
function createIdxTranslationFunction(w, h) {
return function (x, y) {
return y * w + x << 2;
};
}
const srcIdxFunction = createIdxTranslationFunction(w, h);
const dstIdxFunction = createIdxTranslationFunction(nW, nH);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
const srcIdx = srcIdxFunction(x, y);
const pixelRGBA = this.bitmap.data.readUInt32BE(srcIdx);
let dstIdx;
switch (angle) {
case 90:
dstIdx = dstIdxFunction(y, w - x - 1);
break;
case -90:
dstIdx = dstIdxFunction(h - y - 1, x);
break;
case 180:
dstIdx = dstIdxFunction(w - x - 1, h - y - 1);
break;
default:
throw new Error("Unsupported matrix rotation angle");
}
dstBuffer.writeUInt32BE(pixelRGBA, dstIdx);
}
}
this.bitmap.data = dstBuffer;
this.bitmap.width = nW;
this.bitmap.height = nH;
}
/**
* Rotates an image counter-clockwise by an arbitrary number of degrees. NB: 'this' must be a Jimp object.
* @param {number} deg the number of degrees to rotate the image by
* @param {string|boolean} mode (optional) resize mode or a boolean, if false then the width and height of the image will not be changed
*/
function advancedRotate(deg, mode) {
deg %= 360;
const rad = deg * Math.PI / 180;
const cosine = Math.cos(rad);
const sine = Math.sin(rad);
// the final width and height will change if resize == true
let w = this.bitmap.width;
let h = this.bitmap.height;
if (mode === true || typeof mode === "string") {
// resize the image to it maximum dimension and blit the existing image
// onto the center so that when it is rotated the image is kept in bounds
// http://stackoverflow.com/questions/3231176/how-to-get-size-of-a-rotated-rectangle
// Plus 1 border pixel to ensure to show all rotated result for some cases.
w = Math.ceil(Math.abs(this.bitmap.width * cosine) + Math.abs(this.bitmap.height * sine)) + 1;
h = Math.ceil(Math.abs(this.bitmap.width * sine) + Math.abs(this.bitmap.height * cosine)) + 1;
// Ensure destination to have even size to a better result.
if (w % 2 !== 0) {
w++;
}
if (h % 2 !== 0) {
h++;
}
const c = this.cloneQuiet();
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
this.bitmap.data.writeUInt32BE(this._background, idx);
});
const max = Math.max(w, h, this.bitmap.width, this.bitmap.height);
this.resize(max, max, mode);
this.blit(c, this.bitmap.width / 2 - c.bitmap.width / 2, this.bitmap.height / 2 - c.bitmap.height / 2);
}
const bW = this.bitmap.width;
const bH = this.bitmap.height;
const dstBuffer = Buffer.alloc(this.bitmap.data.length);
function createTranslationFunction(deltaX, deltaY) {
return function (x, y) {
return {
x: x + deltaX,
y: y + deltaY
};
};
}
const translate2Cartesian = createTranslationFunction(-(bW / 2), -(bH / 2));
const translate2Screen = createTranslationFunction(bW / 2 + 0.5, bH / 2 + 0.5);
for (let y = 1; y <= bH; y++) {
for (let x = 1; x <= bW; x++) {
const cartesian = translate2Cartesian(x, y);
const source = translate2Screen(cosine * cartesian.x - sine * cartesian.y, cosine * cartesian.y + sine * cartesian.x);
const dstIdx = bW * (y - 1) + x - 1 << 2;
if (source.x >= 0 && source.x < bW && source.y >= 0 && source.y < bH) {
const srcIdx = (bW * (source.y | 0) + source.x | 0) << 2;
const pixelRGBA = this.bitmap.data.readUInt32BE(srcIdx);
dstBuffer.writeUInt32BE(pixelRGBA, dstIdx);
} else {
// reset off-image pixels
dstBuffer.writeUInt32BE(this._background, dstIdx);
}
}
}
this.bitmap.data = dstBuffer;
if (mode === true || typeof mode === "string") {
// now crop the image to the final size
const x = bW / 2 - w / 2;
const y = bH / 2 - h / 2;
this.crop(x, y, w, h);
}
}
export default (() => ({
/**
* Rotates the image counter-clockwise by a number of degrees. By default the width and height of the image will be resized appropriately.
* @param {number} deg the number of degrees to rotate the image by
* @param {string|boolean} mode (optional) resize mode or a boolean, if false then the width and height of the image will not be changed
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
rotate(deg, mode, cb) {
// enable overloading
if (typeof mode === "undefined" || mode === null) {
// e.g. image.resize(120);
// e.g. image.resize(120, null, cb);
// e.g. image.resize(120, undefined, cb);
mode = true;
}
if (typeof mode === "function" && typeof cb === "undefined") {
// e.g. image.resize(120, cb);
cb = mode;
mode = true;
}
if (typeof deg !== "number") {
return throwError.call(this, "deg must be a number", cb);
}
if (typeof mode !== "boolean" && typeof mode !== "string") {
return throwError.call(this, "mode must be a boolean or a string", cb);
}
// use matrixRotate if the angle is a multiple of 90 degrees (eg: 180 or -90) and resize is allowed or not needed.
const matrixRotateAllowed = deg % 90 === 0 && (mode || this.bitmap.width === this.bitmap.height || deg % 180 === 0);
if (matrixRotateAllowed) {
matrixRotate.call(this, deg);
} else {
advancedRotate.call(this, deg, mode, cb);
}
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
}));
//# sourceMappingURL=index.js.map
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
import { ImageCallback } from "@jimp/core";
interface Rotate {
rotate(deg: number, cb?: ImageCallback<this>): this;
rotate(deg: number, mode: string | boolean, cb?: ImageCallback<this>): this;
}
export default function (): Rotate;
+43
View File
@@ -0,0 +1,43 @@
{
"name": "@jimp/plugin-rotate",
"version": "0.22.12",
"description": "Rotate 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-blit": ">=0.3.5",
"@jimp/plugin-crop": ">=0.3.5",
"@jimp/plugin-resize": ">=0.3.5"
},
"devDependencies": {
"@jimp/custom": "^0.22.12",
"@jimp/plugin-blit": "^0.22.12",
"@jimp/plugin-crop": "^0.22.12",
"@jimp/plugin-resize": "^0.22.12",
"@jimp/test-utils": "^0.22.12"
},
"publishConfig": {
"access": "public"
},
"gitHead": "a4a8d6364bbf97629749e196f3b0a4c94c9a7abc"
}
+251
View File
@@ -0,0 +1,251 @@
import { isNodePattern, throwError } from "@jimp/utils";
/**
* Rotates an image counter-clockwise by multiple of 90 degrees. NB: 'this' must be a Jimp object.
*
* This function is based on matrix rotation. Check this to get an initial idea how it works: https://stackoverflow.com/a/8664879/10561909
*
* @param {number} deg the number of degrees to rotate the image by, it should be a multiple of 90
*/
function matrixRotate(deg) {
if (Math.abs(deg) % 90 !== 0) {
throw new Error("Unsupported matrix rotation degree");
}
deg %= 360;
if (Math.abs(deg) === 0) {
// no rotation for 0, 360, -360, 720, -720, ...
return;
}
const w = this.bitmap.width;
const h = this.bitmap.height;
// decide which rotation angle to use
let angle;
switch (deg) {
// 90 degree & -270 degree are same
case 90:
case -270:
angle = 90;
break;
case 180:
case -180:
angle = 180;
break;
case 270:
case -90:
angle = -90;
break;
default:
throw new Error("Unsupported matrix rotation degree");
}
// After this switch block, angle will be 90, 180 or -90
// calculate the new width and height
const nW = angle === 180 ? w : h;
const nH = angle === 180 ? h : w;
const dstBuffer = Buffer.alloc(this.bitmap.data.length);
// function to translate the x, y coordinate to the index of the pixel in the buffer
function createIdxTranslationFunction(w, h) {
return function (x, y) {
return (y * w + x) << 2;
};
}
const srcIdxFunction = createIdxTranslationFunction(w, h);
const dstIdxFunction = createIdxTranslationFunction(nW, nH);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
const srcIdx = srcIdxFunction(x, y);
const pixelRGBA = this.bitmap.data.readUInt32BE(srcIdx);
let dstIdx;
switch (angle) {
case 90:
dstIdx = dstIdxFunction(y, w - x - 1);
break;
case -90:
dstIdx = dstIdxFunction(h - y - 1, x);
break;
case 180:
dstIdx = dstIdxFunction(w - x - 1, h - y - 1);
break;
default:
throw new Error("Unsupported matrix rotation angle");
}
dstBuffer.writeUInt32BE(pixelRGBA, dstIdx);
}
}
this.bitmap.data = dstBuffer;
this.bitmap.width = nW;
this.bitmap.height = nH;
}
/**
* Rotates an image counter-clockwise by an arbitrary number of degrees. NB: 'this' must be a Jimp object.
* @param {number} deg the number of degrees to rotate the image by
* @param {string|boolean} mode (optional) resize mode or a boolean, if false then the width and height of the image will not be changed
*/
function advancedRotate(deg, mode) {
deg %= 360;
const rad = (deg * Math.PI) / 180;
const cosine = Math.cos(rad);
const sine = Math.sin(rad);
// the final width and height will change if resize == true
let w = this.bitmap.width;
let h = this.bitmap.height;
if (mode === true || typeof mode === "string") {
// resize the image to it maximum dimension and blit the existing image
// onto the center so that when it is rotated the image is kept in bounds
// http://stackoverflow.com/questions/3231176/how-to-get-size-of-a-rotated-rectangle
// Plus 1 border pixel to ensure to show all rotated result for some cases.
w =
Math.ceil(
Math.abs(this.bitmap.width * cosine) +
Math.abs(this.bitmap.height * sine)
) + 1;
h =
Math.ceil(
Math.abs(this.bitmap.width * sine) +
Math.abs(this.bitmap.height * cosine)
) + 1;
// Ensure destination to have even size to a better result.
if (w % 2 !== 0) {
w++;
}
if (h % 2 !== 0) {
h++;
}
const c = this.cloneQuiet();
this.scanQuiet(
0,
0,
this.bitmap.width,
this.bitmap.height,
function (x, y, idx) {
this.bitmap.data.writeUInt32BE(this._background, idx);
}
);
const max = Math.max(w, h, this.bitmap.width, this.bitmap.height);
this.resize(max, max, mode);
this.blit(
c,
this.bitmap.width / 2 - c.bitmap.width / 2,
this.bitmap.height / 2 - c.bitmap.height / 2
);
}
const bW = this.bitmap.width;
const bH = this.bitmap.height;
const dstBuffer = Buffer.alloc(this.bitmap.data.length);
function createTranslationFunction(deltaX, deltaY) {
return function (x, y) {
return {
x: x + deltaX,
y: y + deltaY,
};
};
}
const translate2Cartesian = createTranslationFunction(-(bW / 2), -(bH / 2));
const translate2Screen = createTranslationFunction(
bW / 2 + 0.5,
bH / 2 + 0.5
);
for (let y = 1; y <= bH; y++) {
for (let x = 1; x <= bW; x++) {
const cartesian = translate2Cartesian(x, y);
const source = translate2Screen(
cosine * cartesian.x - sine * cartesian.y,
cosine * cartesian.y + sine * cartesian.x
);
const dstIdx = (bW * (y - 1) + x - 1) << 2;
if (source.x >= 0 && source.x < bW && source.y >= 0 && source.y < bH) {
const srcIdx = ((bW * (source.y | 0) + source.x) | 0) << 2;
const pixelRGBA = this.bitmap.data.readUInt32BE(srcIdx);
dstBuffer.writeUInt32BE(pixelRGBA, dstIdx);
} else {
// reset off-image pixels
dstBuffer.writeUInt32BE(this._background, dstIdx);
}
}
}
this.bitmap.data = dstBuffer;
if (mode === true || typeof mode === "string") {
// now crop the image to the final size
const x = bW / 2 - w / 2;
const y = bH / 2 - h / 2;
this.crop(x, y, w, h);
}
}
export default () => ({
/**
* Rotates the image counter-clockwise by a number of degrees. By default the width and height of the image will be resized appropriately.
* @param {number} deg the number of degrees to rotate the image by
* @param {string|boolean} mode (optional) resize mode or a boolean, if false then the width and height of the image will not be changed
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
* @returns {Jimp} this for chaining of methods
*/
rotate(deg, mode, cb) {
// enable overloading
if (typeof mode === "undefined" || mode === null) {
// e.g. image.resize(120);
// e.g. image.resize(120, null, cb);
// e.g. image.resize(120, undefined, cb);
mode = true;
}
if (typeof mode === "function" && typeof cb === "undefined") {
// e.g. image.resize(120, cb);
cb = mode;
mode = true;
}
if (typeof deg !== "number") {
return throwError.call(this, "deg must be a number", cb);
}
if (typeof mode !== "boolean" && typeof mode !== "string") {
return throwError.call(this, "mode must be a boolean or a string", cb);
}
// use matrixRotate if the angle is a multiple of 90 degrees (eg: 180 or -90) and resize is allowed or not needed.
const matrixRotateAllowed =
deg % 90 === 0 &&
(mode || this.bitmap.width === this.bitmap.height || deg % 180 === 0);
if (matrixRotateAllowed) {
matrixRotate.call(this, deg);
} else {
advancedRotate.call(this, deg, mode, cb);
}
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
},
});
+610
View File
@@ -0,0 +1,610 @@
import { Jimp, mkJGD } from "@jimp/test-utils";
import configure from "@jimp/custom";
import blit from "@jimp/plugin-blit";
import crop from "@jimp/plugin-crop";
import resize from "@jimp/plugin-resize";
import rotate from "../src";
import { expectToBeJGD } from "@jimp/test-utils/src";
const jimp = configure({ plugins: [rotate, blit, crop, resize] }, Jimp);
describe("Rotate a image with even size", () => {
let imgSrc = null;
before((done) => {
jimp
.read(
mkJGD(
"▰▴▴▴▪▪▪▰",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▦▪▪▪▴▴▴▦"
)
)
.then((imgJimp) => {
imgSrc = imgJimp;
done();
})
.catch(done);
});
it("1 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(1, true).getJGDSync(),
mkJGD(
"▰▴▴▴▪▪▪▰ ",
"▴▴▴▴▪▪▪▪ ",
"▴▴▴▴▪▪▪▪ ",
"▴▴▴▴▪▪▪▪ ",
"▪▪▪▪▴▴▴▴ ",
"▪▪▪▪▴▴▴▴ ",
"▪▪▪▪▴▴▴▴ ",
"▦▪▪▪▴▴▴▦ ",
" ",
" "
)
);
});
it("91 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(91, true).getJGDSync(),
mkJGD(
" ",
"▰▪▪▪▴▴▴▦ ",
"▪▪▪▪▴▴▴▴ ",
"▪▪▪▪▴▴▴▴ ",
"▪▪▪▪▴▴▴▴ ",
"▴▴▴▴▪▪▪▪ ",
"▴▴▴▴▪▪▪▪ ",
"▴▴▴▴▪▪▪▪ ",
"▰▴▴▴▪▪▪▦ ",
" "
)
);
});
it("30 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(30, true).getJGDSync(),
mkJGD(
" ▰▰ ",
" ▪▪▪▪ ",
" ▴▪▪▪▪▪ ",
"▴▴▴▴▪▪▪▪ ",
"▴▴▴▴▪▪▴▴▴ ",
"▴▴▴▴▪▴▴▴▴▴ ",
" ▴▴▪▪▴▴▴▴▦ ",
" ▪▪▪▪▪▴▴▴ ",
" ▪▪▪▪▪ ",
" ▪▪▪ ",
" ▦ ",
" "
)
);
});
it("45 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(45, true).getJGDSync(),
mkJGD(
" ",
" ▰ ",
" ▪▪▪ ",
" ▪▪▪▪▪ ",
" ▴▴▪▪▪▪▴ ",
" ▴▴▴▴▪▪▴▴▴ ",
"▰▰▴▴▴▴▴▴▴▴▦ ",
" ▴▴▴▴▪▪▴▴▴ ",
" ▴▴▪▪▪▪▴ ",
" ▪▪▪▪▪ ",
" ▪▪▪ ",
" ▦ ",
" ",
" "
)
);
});
it("60 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(60, true).getJGDSync(),
mkJGD(
" ▰ ",
" ▪▪▪ ",
" ▪▪▪▪▪ ",
" ▪▪▪▪▪▴▴▴ ",
" ▴▴▪▪▴▴▴▴▦ ",
"▴▴▴▴▪▴▴▴▴▴ ",
"▴▴▴▴▪▪▴▴▴ ",
"▴▴▴▴▪▪▪▪ ",
" ▴▪▪▪▪▪ ",
" ▪▪▪▪ ",
" ▦▦ ",
" "
)
);
});
it("90 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(90, true).getJGDSync(),
mkJGD(
"▰▪▪▪▴▴▴▦",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▰▴▴▴▪▪▪▦"
)
);
});
it("-90 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(-90, true).getJGDSync(),
mkJGD(
"▦▪▪▪▴▴▴▰",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▦▴▴▴▪▪▪▰"
)
);
});
it("120 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(120, true).getJGDSync(),
mkJGD(
" ",
" ▴▦ ",
" ▴▴▴▴ ",
" ▪▪▴▴▴▴ ",
"▰▪▪▪▴▴▴▴▪ ",
"▰▪▪▪▪▴▴▪▪▪ ",
" ▪▪▪▪▪▪▪▪▪ ",
" ▪▪▴▴▴▪▪▪▪▦ ",
" ▴▴▴▴▴▪▪ ",
" ▴▴▴▴▪ ",
" ▴▴▴ ",
" "
)
);
});
it("135 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(135, true).getJGDSync(),
mkJGD(
" ",
" ",
" ▦ ",
" ▴▴▴ ",
" ▴▴▴▴▴ ",
" ▪▪▴▴▴▪▪ ",
" ▪▪▪▪▴▪▪▪▪ ",
" ▰▪▪▪▪▴▪▪▪▪▦ ",
" ▪▪▪▴▴▴▪▪▪ ",
" ▪▴▴▴▴▴▪ ",
" ▴▴▴▴▴ ",
" ▴▰▴ ",
" ▰ ",
" "
)
);
});
it("180 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(180, true).getJGDSync(),
mkJGD(
"▦▴▴▴▪▪▪▦",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▰▪▪▪▴▴▴▰"
)
);
});
it("225 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(225, true).getJGDSync(),
mkJGD(
" ",
" ▦ ",
" ▪▪▪ ",
" ▪▪▪▪▪ ",
" ▴▪▪▪▪▴▴ ",
" ▴▴▴▪▪▴▴▴▴ ",
" ▦▴▴▴▴▴▴▴▴▰▰ ",
" ▴▴▴▪▪▴▴▴▴ ",
" ▴▪▪▪▪▴▴ ",
" ▪▪▪▪▪ ",
" ▪▪▪ ",
" ▰ ",
" ",
" "
)
);
});
it("270 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(270, true).getJGDSync(),
mkJGD(
"▦▪▪▪▴▴▴▰",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▦▴▴▴▪▪▪▰"
)
);
});
it("315 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(315, true).getJGDSync(),
mkJGD(
" ▰ ",
" ▴▰▴ ",
" ▴▴▴▴▴ ",
" ▪▴▴▴▴▴▪ ",
" ▪▪▪▴▴▴▪▪▪ ",
" ▦▪▪▪▪▴▪▪▪▪▰ ",
" ▪▪▪▪▴▪▪▪▪ ",
" ▪▪▴▴▴▪▪ ",
" ▴▴▴▴▴ ",
" ▴▴▴ ",
" ▦ ",
" ",
" ",
" "
)
);
});
it("360 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(360, true).getJGDSync(),
mkJGD(
"▰▴▴▴▪▪▪▰",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▦▪▪▪▴▴▴▦"
)
);
});
});
describe("Rotate a image with odd size", () => {
let imgSrc = null;
before((done) => {
jimp
.read(
mkJGD(
"▴▴▴▦▪▪▪",
"▴▴▴▦▪▪▪",
"▴▴▴▦▪▪▪",
"▦▦▦▦▦▦▦",
"▴▴▴▦▴▴▴",
"▴▴▴▦▴▴▴",
"▴▴▴▦▴▴▴"
)
)
.then((imgJimp) => {
imgSrc = imgJimp;
done();
})
.catch(done);
});
it("45 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(45, true).getJGDSync(),
mkJGD(
" ",
" ▪ ",
" ▪▪▪ ",
" ▦▪▪▪▦ ",
" ▴▴▦▪▦▴▴ ",
" ▴▴▴▴▦▴▴▴▴ ",
" ▴▴▦▴▦▴▴ ",
" ▦▴▴▴▦ ",
" ▴▴▴ ",
" ▴ ",
" ",
" "
)
);
});
it("135 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(135, true).getJGDSync(),
mkJGD(
" ",
" ▴ ",
" ▴▴▴ ",
" ▦▴▴▴▦ ",
" ▪▪▦▴▦▴▴ ",
" ▪▪▪▪▦▴▴▴▴ ",
" ▪▪▦▴▦▴▴ ",
" ▦▴▴▴▦ ",
" ▴▴▴ ",
" ▴ ",
" ",
" "
)
);
});
it("225 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(225, true).getJGDSync(),
mkJGD(
" ",
" ▴ ",
" ▴▴▴ ",
" ▦▴▴▴▦ ",
" ▴▴▦▴▦▴▴ ",
" ▴▴▴▴▦▴▴▴▴ ",
" ▴▴▦▪▦▴▴ ",
" ▦▪▪▪▦ ",
" ▪▪▪ ",
" ▪ ",
" ",
" "
)
);
});
it("315 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(315, true).getJGDSync(),
mkJGD(
" ",
" ▴ ",
" ▴▴▴ ",
" ▦▴▴▴▦ ",
" ▴▴▦▴▦▪▪ ",
" ▴▴▴▴▦▪▪▪▪ ",
" ▴▴▦▴▦▪▪ ",
" ▦▴▴▴▦ ",
" ▴▴▴ ",
" ▴ ",
" ",
" "
)
);
});
});
describe("Rotate a non-square image", () => {
let imgSrc = null;
before((done) => {
jimp
.read(mkJGD("▴▴▴▴▪▪▪▪", "▴▴▴▴▪▪▪▪", "▦▦▦▦▴▴▴▴", "▦▦▦▦▴▴▴▴"))
.then((imgJimp) => {
imgSrc = imgJimp;
done();
})
.catch(done);
});
it("1 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(1, true).getJGDSync(),
mkJGD(
"▴▴▴▴▪▪▪▪ ",
"▴▴▴▴▪▪▪▪ ",
"▦▦▦▦▴▴▴▴ ",
"▦▦▦▦▴▴▴▴ ",
" ",
" "
)
);
});
it("10 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(10, true).getJGDSync(),
mkJGD(
" ▪ ",
" ▴▴▴▪▪▪▪ ",
"▴▴▴▴▪▪▪▴ ",
"▴▴▦▦▴▴▴▴ ",
"▦▦▦▦▴▴▴ ",
"▦▦ ",
" ",
" "
)
);
});
it("30 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(30, true).getJGDSync(),
mkJGD(
" ",
" ▪▪ ",
" ▪▪▪▪ ",
" ▴▴▪▪▴▴▴ ",
"▴▴▴▦▴▴▴ ",
"▴▴▦▦▴▴ ",
"▦▦▦▦ ",
" ▦ ",
" ",
" "
)
);
});
it("45 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(45, true).getJGDSync(),
mkJGD(
" ",
" ▪▪ ",
" ▪▪▪▴ ",
" ▴▪▪▴▴▴ ",
" ▴▴▴▴▴▴ ",
"▴▴▴▦▦▴ ",
"▴▴▦▦▦ ",
" ▦▦▦ ",
" ▦ ",
" "
)
);
});
it("90 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(90, true).getJGDSync(),
mkJGD("▪▪▴▴", "▪▪▴▴", "▪▪▴▴", "▪▪▴▴", "▴▴▦▦", "▴▴▦▦", "▴▴▦▦", "▴▴▦▦")
);
});
it("-90 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(-90, true).getJGDSync(),
mkJGD("▦▦▴▴", "▦▦▴▴", "▦▦▴▴", "▦▦▴▴", "▴▴▪▪", "▴▴▪▪", "▴▴▪▪", "▴▴▪▪")
);
});
it("135 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(135, true).getJGDSync(),
mkJGD(
" ",
" ▴ ",
" ▴▴▴ ",
" ▪▪▴▴▴ ",
" ▪▪▪▴▦▦ ",
" ▪▪▴▦▦▦ ",
" ▴▴▴▦▦▦ ",
" ▴▴▴▦ ",
" ▴▴ ",
" "
)
);
});
it("180 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(180, true).getJGDSync(),
mkJGD("▴▴▴▴▦▦▦▦", "▴▴▴▴▦▦▦▦", "▪▪▪▪▴▴▴▴", "▪▪▪▪▴▴▴▴")
);
});
it("225 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(225, true).getJGDSync(),
mkJGD(
" ▦ ",
" ▦▦▦ ",
" ▦▦▦▴▴ ",
" ▴▦▦▴▴▴ ",
" ▴▴▴▴▴▴ ",
" ▴▴▴▪▪▴ ",
" ▴▪▪▪ ",
" ▪▪ ",
" ",
" "
)
);
});
it("315 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(315, true).getJGDSync(),
mkJGD(
" ▴▴ ",
" ▦▴▴▴ ",
"▦▦▦▴▴▴ ",
" ▦▦▦▴▪▪ ",
" ▦▦▴▪▪▪ ",
" ▴▴▴▪▪ ",
" ▴▴▴ ",
" ▴ ",
" ",
" "
)
);
});
it("-180 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(-180, true).getJGDSync(),
mkJGD("▴▴▴▴▦▦▦▦", "▴▴▴▴▦▦▦▦", "▪▪▪▪▴▴▴▴", "▪▪▪▪▴▴▴▴")
);
});
it("-270 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(-270, true).getJGDSync(),
mkJGD("▪▪▴▴", "▪▪▴▴", "▪▪▴▴", "▪▪▴▴", "▴▴▦▦", "▴▴▦▦", "▴▴▦▦", "▴▴▦▦")
);
});
});
describe("Rotate a non-square image without resizing", () => {
let imgSrc = null;
before((done) => {
jimp
.read(mkJGD("□□□□□□□□", "▹▹▹▹▹▹▹▹", "▿▿▿▿▿▿▿▿", "□□□□□□□□"))
.then((imgJimp) => {
imgSrc = imgJimp;
done();
})
.catch(done);
});
it("90 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(90, false).getJGDSync(),
mkJGD(" □▹▿□ ", " □▹▿□ ", " □▹▿□ ", " □▹▿□ ")
);
});
it("180 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(180, false).getJGDSync(),
mkJGD("□□□□□□□□", "▿▿▿▿▿▿▿▿", "▹▹▹▹▹▹▹▹", "□□□□□□□□")
);
});
it("270 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(270, false).getJGDSync(),
mkJGD(" □▿▹□ ", " □▿▹□ ", " □▿▹□ ", " □▿▹□ ")
);
});
it("45 degrees", () => {
expectToBeJGD(
imgSrc.clone().rotate(45, false).getJGDSync(),
mkJGD(" □▹▹▿□□ ", "□▹▹▿□□ ", "▹▹▿□□ ", "▹▿□□ ")
);
});
});