Spaces:
Sleeping
Sleeping
File size: 2,276 Bytes
3530df7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | 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("Rotate a image with even size", () => {
const imgSrc = jimp.fromBitmap(
makeTestImage(
"▰▴▴▴▪▪▪▰",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▴▴▴▴▪▪▪▪",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▪▪▪▪▴▴▴▴",
"▦▪▪▪▴▴▴▦",
),
);
const angles = [
1, 91, 30, 45, 60, 90, -90, 120, 135, 180, 225, 270, 315, 360,
];
angles.forEach((angle) => {
test(`${angle} degrees`, () => {
expect(imgSrc.clone().rotate(angle)).toMatchSnapshot();
});
});
});
describe("Rotate a image with odd size", () => {
const imgSrc = jimp.fromBitmap(
makeTestImage(
"▴▴▴▦▪▪▪",
"▴▴▴▦▪▪▪",
"▴▴▴▦▪▪▪",
"▦▦▦▦▦▦▦",
"▴▴▴▦▴▴▴",
"▴▴▴▦▴▴▴",
"▴▴▴▦▴▴▴",
),
);
const angles = [45, 135, 225, 315];
angles.forEach((angle) => {
test(`${angle} degrees`, () => {
expect(imgSrc.clone().rotate(angle)).toMatchSnapshot();
});
});
});
describe("Rotate a non-square image", () => {
const imgSrc = jimp.fromBitmap(
makeTestImage("▴▴▴▴▪▪▪▪", "▴▴▴▴▪▪▪▪", "▦▦▦▦▴▴▴▴", "▦▦▦▦▴▴▴▴"),
);
const angles = [1, 10, 30, 45, 90, -90, 135, 180, 225, 315, -180, -270];
angles.forEach((angle) => {
test(`${angle} degrees`, () => {
expect(imgSrc.clone().rotate(angle)).toMatchSnapshot();
});
});
});
describe("Rotate a non-square image without resizing", () => {
const imgSrc = jimp.fromBitmap(
makeTestImage("□□□□□□□□", "▹▹▹▹▹▹▹▹", "▿▿▿▿▿▿▿▿", "□□□□□□□□"),
);
const angles = [90, 180, 270, 45];
angles.forEach((angle) => {
test(`${angle} degrees`, () => {
expect(
imgSrc.clone().rotate({ deg: angle, mode: false }),
).toMatchSnapshot();
});
});
});
|