-
Notifications
You must be signed in to change notification settings - Fork 1
/
e2e-test.js
99 lines (77 loc) · 2.39 KB
/
e2e-test.js
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
/* eslint-disable no-console */
var nodeFLIF = require('./index.js');
function runCommandSync (executable, args) {
var exec = require('child_process').execSync;
var executableAndArgs = executable + ' ' + args;
var child = exec(executableAndArgs);
return child.toString().trim();
}
// Test converting 1 flif to 1 png
var decodeParams = {
input: './sample/cat.flif',
output: './sample/decode-test.png',
overwrite: true
};
nodeFLIF.decode(decodeParams, function (data) {
console.log('Decode cat.flif -> decode-test.png finished');
if (data) {
console.log(data);
}
});
// Test converting 1 png to 1 flif
var encodeParams = {
input: './sample/cat.png',
output: './sample/encode-test.flif',
overwrite: true,
async: false,
// Pixel predictor for each plane: 'average', 'median gradient', 'median number', 'mixed', default is 'heuristically'
guess: {
y: 'heuristically',
co: 'heuristically',
cg: 'heuristically',
alpha: 'heuristically',
lookback: 'heuristically'
}
};
console.log(nodeFLIF.encode(encodeParams));
console.log('Encode cat.png -> encode-test.flif finished.');
// Verify the above flif was created properly by decoding to png
var decodeParams2 = {
input: './sample/encode-test.flif',
output: './sample/decode-encode-test.png',
overwrite: true
};
nodeFLIF.decode(decodeParams2, function (data) {
console.log('Decode encode-test.flif -> decode-encode-test.png finished');
if (data) {
console.log(data);
}
});
// Identify data in a flif
var catData = nodeFLIF.identify('./sample/cat.flif');
console.log(catData);
console.log('Identified cat.flif');
// Create an animated flif
var encodeAnimParams = {
input: [
'./sample/catrun01.png',
'./sample/catrun02.png',
'./sample/catrun03.png',
'./sample/catrun04.png',
'./sample/catrun05.png',
'./sample/catrun06.png'
],
output: './sample/encode-anim-test.flif',
overwrite: true,
frameDelay: [0]
};
nodeFLIF.encode(encodeAnimParams, function (data) {
console.log('Encode catrun01-06.png -> encode-anim-test.flif finished.');
if (data) {
console.log(data);
}
});
// Run Libflif
var open = require('open');
open('http://localhost:8000/node_modules/libflif.js/index.html');
runCommandSync('node', './node_modules/npm-free-server/dist/server.js');