-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreduce-image-task.js
49 lines (42 loc) · 1019 Bytes
/
reduce-image-task.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
// This task is to be run separately using child_process.execFile
let Jimp = require('jimp'),
path = require('path'),
argv = require('argv'),
_ = require('lodash'),
File = require('./file');
argv.option({
name: 'image',
type: 'path'
});
argv.option({
name: 'out',
type: 'path'
});
let args = argv.run().options;
let imagePath = args.image;
Jimp.read(imagePath, (err, img) => {
if (err) {
process.stderr.write(err.toString());
process.exit(1);
};
let fileName = _.last(imagePath.split('/'));
let outputPath = path.join(args.out, fileName);
img
.resize(500, Jimp.AUTO)
.quality(50)
//.greyscale()
.blur(7)
//.opacity(0.5)
.brightness(0.5)
//.opaque()
.write(outputPath, () => {
let originalSize = File.size(imagePath) / 1000; // KB
let outputSize = File.size(outputPath) / 1000;
process.stdout.write(JSON.stringify({
fileName,
originalSize,
outputSize,
}));
process.exit();
});
});