Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/jpeg/test/jpeg.test.js
1126 views
1
import { Jimp, getTestDir } from '@jimp/test-utils';
2
import configure from '@jimp/custom';
3
4
import jpeg from '../src';
5
6
const jimp = configure({ types: [jpeg] }, Jimp);
7
8
describe('JPEG', () => {
9
const imagesDir = getTestDir(__dirname) + '/images';
10
11
it('load JPG', async () => {
12
const image = await jimp.read(imagesDir + '/cops.jpg');
13
14
image.getPixelColor(10, 10).should.be.equal(0x3f4a02ff);
15
image.getPixelColor(220, 190).should.be.equal(0x5d94b6ff);
16
image.getPixelColor(350, 130).should.be.equal(0xdf7944ff);
17
});
18
19
it('load JPG with fill bytes', async () => {
20
const image = await jimp.read(imagesDir + '/fillbytes.jpg');
21
22
image.getPixelColor(10, 10).should.be.equal(0xaeb8c3ff);
23
image.getPixelColor(220, 190).should.be.equal(0x262b21ff);
24
image.getPixelColor(350, 130).should.be.equal(0x4e5d30ff);
25
});
26
27
it('export JPG', async () => {
28
const image = await jimp.read({
29
width: 3,
30
height: 3,
31
data: [
32
0xff0000ff,
33
0xff0080ff,
34
0xff00ffff,
35
0xff0080ff,
36
0xff00ffff,
37
0x8000ffff,
38
0xff00ffff,
39
0x8000ffff,
40
0x0000ffff
41
]
42
});
43
image.quality(50);
44
const buffer = await image.getBufferAsync('image/jpeg');
45
46
buffer.toString().should.match(/^.{3,9}JFIF\u0000/);
47
});
48
});
49
50