-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathhalftone.js
More file actions
32 lines (30 loc) · 1.21 KB
/
Copy pathhalftone.js
File metadata and controls
32 lines (30 loc) · 1.21 KB
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
"use strict";
var args = require('./commargs.js')(),
fs = require('fs'),
F = require('./filterwithcanvas.js'),
parallel = !!args.options['parallel'],
halftone = F.CompositeFilter([
F.ColorMatrixFilter().grayscale(),
F.HalftoneFilter(1).threshold(0.4)/*.setMode(F.MODE.GRAY)*/
]);
console.log('Filter runs "' + (parallel ? 'parallel' : 'synchronous') + '"');
if (parallel) halftone.worker(true);
console.log('Loading..');
fs.readFile(__dirname+'/che.jpg', function(err, buf) {
if (err) console.log('error while reading image: ' + err.toString());
F.Image.load(buf, function(img) {
console.log('Procesing..');
halftone.apply(img, function() {
if (parallel) halftone.worker(false);
console.log('Saving..');
img.oCanvas.toPNG().then(function(png) {
fs.writeFile(__dirname+'/che_halfone.png', png, function(err) {
if (err) console.log('error while saving image: ' + err.toString());
else console.log('image saved');
})
}).catch(function(err) {
console.log('error while exporting image: ' + err.toString());
});
});
});
});