Spaces:
Sleeping
Sleeping
File size: 1,346 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 | import { expect, test, describe } from "vitest";
import { createJimp } from "@jimp/core";
import { makeTestImage } from "@jimp/test-utils";
import { methods as crop } from "./index.js";
const jimp = createJimp({ plugins: [crop], formats: [] });
describe("crop", () => {
// 6x5 size
const testImage = makeTestImage(
" ββ ",
" ββ¦β¦β ",
"ββ¦β¦β¦β¦β",
" ββ¦β¦β ",
" ββ ",
);
test("full width from top", () => {
expect(
jimp.fromBitmap(testImage).crop({ x: 0, y: 0, w: 6, h: 2 }),
).toMatchSnapshot();
});
test("full width from bottom", () => {
expect(
jimp.fromBitmap(testImage).crop({ x: 0, y: 3, w: 6, h: 2 }),
).toMatchSnapshot();
});
test("full width from middle", () => {
expect(
jimp.fromBitmap(testImage).crop({ x: 0, y: 2, w: 6, h: 2 }),
).toMatchSnapshot();
});
test("full height from left", () => {
expect(
jimp.fromBitmap(testImage).crop({ x: 0, y: 0, w: 2, h: 5 }),
).toMatchSnapshot();
});
test("full height from right", () => {
expect(
jimp.fromBitmap(testImage).crop({ x: 4, y: 0, w: 2, h: 5 }),
).toMatchSnapshot();
});
test("full height from middle", () => {
expect(
jimp.fromBitmap(testImage).crop({ x: 2, y: 0, w: 2, h: 5 }),
).toMatchSnapshot();
});
});
|