-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-sharp.js
54 lines (41 loc) · 1.44 KB
/
test-sharp.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
"use strict";
var Promise = require('bluebird'),
fs = Promise.promisifyAll(require('fs')),
globAsync = Promise.promisify(require('glob')),
sharp = require('sharp'),
sharpCreateEmpty = require('./lib/sharp-create-empty'),
sharpReloadImage = require('./lib/sharp-reload-image'),
Benchmark = require('benchmark');
var inputDir = './input',
tWidth = 450,
tHeight = 300,
rows = 9,
cols = 9,
chnls = 3;
return globAsync(inputDir + '/*.jpg')
.then(function(imgInputPaths) {
var suite = new Benchmark('sharp', {'defer': true, 'fn': function(deferred) {
var imgPage = sharpCreateEmpty(cols*tWidth, rows*tHeight, chnls);
Promise.each(imgInputPaths, function(imgInputPath, index) {
let col = (index % cols),
row = Math.floor(index / cols);
console.log('overlaying with row ' + (row+1) + ', col ' + (col+1) + '...');
imgPage.overlayWith(imgInputPath, {left: col*tWidth, top: row*tHeight});
return sharpReloadImage(imgPage)
.then(function(imgPageNew) {
imgPage = imgPageNew;
});
})
.then(function() {
return imgPage.toFile('./output/output-sharp.png');
})
.then(function() {
console.log('Done.');
deferred.resolve();
});
}})
.on('cycle', function(event) {
console.log(String(event.target));
})
.run({ 'async': true });
});