File size: 1,678 Bytes
80ce16c | 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 | import { Jimp, mkJGD } from "@jimp/test-utils";
import configure from "@jimp/custom";
import crop from "../src";
const jimp = configure({ plugins: [crop] }, Jimp);
describe("crop", () => {
// 6x5 size
const testImage = mkJGD(" ◆◆ ", " ◆▦▦◆ ", "◆▦▦▦▦◆", " ◆▦▦◆ ", " ◆◆ ");
it("full width from top", async () => {
const imgSrc = await jimp.read(testImage);
imgSrc
.crop(0, 0, 6, 2)
.getJGDSync()
.should.be.sameJGD(mkJGD(" ◆◆ ", " ◆▦▦◆ "));
});
it("full width from bottom", async () => {
const imgSrc = await jimp.read(testImage);
imgSrc
.crop(0, 3, 6, 2)
.getJGDSync()
.should.be.sameJGD(mkJGD(" ◆▦▦◆ ", " ◆◆ "));
});
it("full width from middle", async () => {
const imgSrc = await jimp.read(testImage);
imgSrc
.crop(0, 2, 6, 2)
.getJGDSync()
.should.be.sameJGD(mkJGD("◆▦▦▦▦◆", " ◆▦▦◆ "));
});
it("full height from left", async () => {
const imgSrc = await jimp.read(testImage);
imgSrc
.crop(0, 0, 2, 5)
.getJGDSync()
.should.be.sameJGD(mkJGD(" ", " ◆", "◆▦", " ◆", " "));
});
it("full height from right", async () => {
const imgSrc = await jimp.read(testImage);
imgSrc
.crop(4, 0, 2, 5)
.getJGDSync()
.should.be.sameJGD(mkJGD(" ", "◆ ", "▦◆", "◆ ", " "));
});
it("full height from middle", async () => {
const imgSrc = await jimp.read(testImage);
imgSrc
.crop(2, 0, 2, 5)
.getJGDSync()
.should.be.sameJGD(mkJGD("◆◆", "▦▦", "▦▦", "▦▦", "◆◆"));
});
});
|