-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglitcher.js
41 lines (34 loc) · 926 Bytes
/
glitcher.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
const Jimp = require('jimp');
const {promisify} = require('./utils');
const Colors = require('./colors');
const glitch = require('./glitch');
module.exports = function(input, {
method,
treshold,
invert,
consequentRows,
minimalSequence,
columns
}) {
const findBy = Colors[method];
const predicates = [x => findBy(x) > treshold, x => findBy(x) < treshold];
if (invert) { predicates.reverse(); }
const [startPredicate, endPredicate] = predicates;
const start = Date.now();
return Jimp.read(input)
.then(img => {
const filename = typeof input === 'string'
? input
: `${img.bitmap.width}x${img.bitmap.height}`;
glitch(img, {
sortBy: findBy,
startPredicate,
endPredicate,
consequentRows,
minimalSequence,
columns
});
console.log(`Glitched ${filename} in ${Date.now() - start}ms`);
return img;
});
}