-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
95 lines (83 loc) · 2.35 KB
/
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
'use strict';
const fs = require('fs');
const readline = require('readline');
const { Image } = require('./lib');
function dumpMemoryUsage(data) {
global.gc();
console.log(process.memoryUsage());
}
function readFilePromise(filePath) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, (err, data) => {
if (err) return reject(err);
resolve(data);
});
});
}
(async () => {
console.log(`PID ${process.pid}`);
const imEmpty = new Image('300x300', 'red');
await imEmpty.write('output/empty.jpg');
return;
const buffer = await readFilePromise('input/test.jpg');
const baseImage = new Image();
await baseImage.read(buffer);
const im1 = new Image(baseImage);
await im1.rotate();
await im1.resize(600, 600, 'areafill');
await im1.write('output/test-autorotate-resize.jpg');
// await (new Image(baseImage)).process({
// autorotate: true,
// strip: true,
// output: {
// file: `output/test-autorotate.jpg`,
// },
// });
// await (new Image(baseImage)).process({
// autorotate: true,
// // resize: "3024",
// resize: "300x300",
// extent: {
// size: "300x300",
// color: "red",
// },
// strip: true,
// output: {
// file: `output/test-autorotate-resize.jpg`,
// },
// });
// await (new Image(baseImage)).process({
// autorotate: true,
// crop: "3024x1701^",
// strip: true,
// output: {
// file: `output/test-autorotate-crop.jpg`,
// },
// });
dumpMemoryUsage();
return;
let index = 0;
promises = []
do {
const output = `output/test-${++index}.jpg`;
promises.push((new Image(baseImage)).process({
output: {
file: output,
},
autorotate: true,
strip: true,
}));
} while (index < 10);
Promise.all(promises).then((files) => {
console.log(files);
}).then(dumpMemoryUsage);
return;
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false,
});
rl.on('line', async (line) => {
// await test(baseImage.copy(), buffer, ++i).then(dumpMemoryUsage);
});
})();