Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-crop/test/crop.test.js
1129 views
1
import { Jimp, mkJGD } from '@jimp/test-utils';
2
import configure from '@jimp/custom';
3
4
import crop from '../src';
5
6
const jimp = configure({ plugins: [crop] }, Jimp);
7
8
describe('crop', () => {
9
// 6x5 size
10
const testImage = mkJGD(' ◆◆ ', ' ◆▦▦◆ ', '◆▦▦▦▦◆', ' ◆▦▦◆ ', ' ◆◆ ');
11
12
it('full width from top', async () => {
13
const imgSrc = await jimp.read(testImage);
14
15
imgSrc
16
.crop(0, 0, 6, 2)
17
.getJGDSync()
18
.should.be.sameJGD(mkJGD(' ◆◆ ', ' ◆▦▦◆ '));
19
});
20
21
it('full width from bottom', async () => {
22
const imgSrc = await jimp.read(testImage);
23
24
imgSrc
25
.crop(0, 3, 6, 2)
26
.getJGDSync()
27
.should.be.sameJGD(mkJGD(' ◆▦▦◆ ', ' ◆◆ '));
28
});
29
30
it('full width from middle', async () => {
31
const imgSrc = await jimp.read(testImage);
32
33
imgSrc
34
.crop(0, 2, 6, 2)
35
.getJGDSync()
36
.should.be.sameJGD(mkJGD('◆▦▦▦▦◆', ' ◆▦▦◆ '));
37
});
38
39
it('full height from left', async () => {
40
const imgSrc = await jimp.read(testImage);
41
42
imgSrc
43
.crop(0, 0, 2, 5)
44
.getJGDSync()
45
.should.be.sameJGD(mkJGD(' ', ' ◆', '◆▦', ' ◆', ' '));
46
});
47
48
it('full height from right', async () => {
49
const imgSrc = await jimp.read(testImage);
50
51
imgSrc
52
.crop(4, 0, 2, 5)
53
.getJGDSync()
54
.should.be.sameJGD(mkJGD(' ', '◆ ', '▦◆', '◆ ', ' '));
55
});
56
57
it('full height from middle', async () => {
58
const imgSrc = await jimp.read(testImage);
59
60
imgSrc
61
.crop(2, 0, 2, 5)
62
.getJGDSync()
63
.should.be.sameJGD(mkJGD('◆◆', '▦▦', '▦▦', '▦▦', '◆◆'));
64
});
65
});
66
67