Spaces:
Sleeping
Sleeping
File size: 3,823 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | import { expect, test, describe } from "vitest";
import { makeTestImage } from "@jimp/test-utils";
import { createJimp } from "@jimp/core";
import { methods, ResizeStrategy } from "./index.js";
const jimp = createJimp({ plugins: [methods], formats: [] });
describe("Resize images", () => {
const testImages = [
{
title: "max contrast 8x8",
src: jimp.fromBitmap(
makeTestImage(
"■■■■□□□□",
"■■■■□□□□",
"■■■■□□□□",
"■■■■□□□□",
"□□□□■■■■",
"□□□□■■■■",
"□□□□■■■■",
"□□□□■■■■"
)
),
tests: [
{ mode: "default", size: { height: 4, width: 4 } },
{ mode: "NEAREST_NEIGHBOR", size: { height: 4, width: 4 } },
{ mode: "BILINEAR", size: { height: 4, width: 4 } },
{ mode: "BICUBIC", size: { height: 4, width: 4 } },
{ mode: "HERMITE", size: { height: 4, width: 4 } },
{ mode: "BEZIER", size: { height: 4, width: 4 } },
{ mode: "default", size: { height: 5, width: 2 } },
{ mode: "NEAREST_NEIGHBOR", size: { height: 5, width: 2 } },
{ mode: "BILINEAR", size: { height: 5, width: 2 } },
{ mode: "BICUBIC", size: { height: 5, width: 2 } },
{ mode: "HERMITE", size: { height: 5, width: 2 } },
{ mode: "BEZIER", size: { height: 5, width: 2 } },
],
},
/**********************************************************************/
{
title: "max contrast 12x12 with dots",
src: jimp.fromBitmap(
makeTestImage(
"■■■■■■□□□□□□",
"■■■■■■□□□□□□",
"■■■□■■□□■□□□",
"■■■■■■□□□□□□",
"■■■■■■□□□□□□",
"■■■■■■□□□□□□",
"□□□□□□■■■■■■",
"□□□□□□■■■■■■",
"□□□□□□■■■■■■",
"□□□■□□■■□■■■",
"□□□□□□■■■■■■",
"□□□□□□■■■■■■"
)
),
tests: [
{ mode: "default", size: { height: 6, width: 6 } },
{ mode: "NEAREST_NEIGHBOR", size: { height: 6, width: 6 } },
{ mode: "BILINEAR", size: { height: 6, width: 6 } },
{ mode: "BICUBIC", size: { height: 6, width: 6 } },
{ mode: "HERMITE", size: { height: 6, width: 6 } },
{ mode: "BEZIER", size: { height: 6, width: 6 } },
],
},
/**********************************************************************/
{
title: "mutch contrast 4x4",
src: jimp.fromBitmap(makeTestImage("▩▩▥▥", "▩▩▥▥", "▥▥▩▩", "▥▥▩▩")),
tests: [
{ mode: "default", size: { height: 6, width: 6 } },
{ mode: "NEAREST_NEIGHBOR", size: { height: 6, width: 6 } },
{ mode: "BILINEAR", size: { height: 6, width: 6 } },
{ mode: "BICUBIC", size: { height: 6, width: 6 } },
{ mode: "HERMITE", size: { height: 6, width: 6 } },
{ mode: "BEZIER", size: { height: 6, width: 6 } },
],
},
];
testImages.forEach((image) => {
describe(image.title, () => {
image.tests.forEach(({ mode: modeType, size }) => {
test(`to ${modeType} ${size.width}x${size.height}`, () => {
const mode = ResizeStrategy[modeType as keyof typeof ResizeStrategy];
expect(
image.src.clone().resize({
w: size.width,
h: size.height,
mode,
})
).toMatchSnapshot();
});
});
});
});
});
|