Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/png/test/png.test.js
1126 views
1
import { Jimp, getTestDir } from '@jimp/test-utils';
2
import configure from '@jimp/custom';
3
4
import png from '../src';
5
6
const jimp = configure({ types: [png] }, Jimp);
7
8
describe('PNG', () => {
9
const imagesDir = getTestDir(__dirname) + '/images';
10
11
it('load PNG', async () => {
12
const image = await jimp.read(imagesDir + '/dice.png');
13
14
image.getPixelColor(10, 10).should.be.equal(0x00000000);
15
image.getPixelColor(160, 80).should.be.equal(0x1c1cd4ff);
16
image.getPixelColor(400, 250).should.be.equal(0x7e0c0cda);
17
});
18
19
it('export PNG', async () => {
20
const jgd = await jimp.read({
21
width: 3,
22
height: 3,
23
data: [
24
0xff0000ff,
25
0xff0080ff,
26
0xff00ffff,
27
0xff0080ff,
28
0xff00ffff,
29
0x8000ffff,
30
0xff00ffff,
31
0x8000ffff,
32
0x0000ffff
33
]
34
});
35
const buffer = await jgd.getBufferAsync('image/png');
36
37
buffer.toString().should.match(/^.PNG\r\n/);
38
});
39
40
it('should use png options', async () => {
41
const jgd = await jimp.read({
42
width: 20,
43
height: 20,
44
data: [
45
0xff0000ff,
46
0xff0080ff,
47
0xff00ffff,
48
0xff0080ff,
49
0xff00ffff,
50
0x8000ffff,
51
0xff00ffff,
52
0x8000ffff,
53
0x0000ffff,
54
0xff0000ff,
55
0xff0080ff,
56
0xff00ffff,
57
0xff0080ff,
58
0xff00ffff,
59
0x8000ffff,
60
0xff00ffff,
61
0x8000ffff,
62
0x0000ffff,
63
0xff0000ff,
64
0xff0080ff,
65
0xff00ffff,
66
0xff0080ff,
67
0xff00ffff,
68
0x8000ffff,
69
0xff00ffff,
70
0x8000ffff,
71
0x0000ffff,
72
0xff0000ff,
73
0xff0080ff,
74
0xff00ffff,
75
0xff0080ff,
76
0xff00ffff,
77
0x8000ffff,
78
0xff00ffff,
79
0x8000ffff,
80
0x0000ffff
81
]
82
});
83
84
const image = await jgd
85
.deflateStrategy(0)
86
.colorType(0)
87
.getBufferAsync(Jimp.MIME_PNG);
88
89
const expected = await jimp.read(imagesDir + '/options.png');
90
const expectedBuffer = await expected
91
.deflateStrategy(0)
92
.colorType(0)
93
.getBufferAsync(Jimp.MIME_PNG);
94
95
image.should.be.deepEqual(expectedBuffer);
96
});
97
});
98
99