-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
47 lines (41 loc) · 1.22 KB
/
utils.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
var exports = module.exports = {};
var ImageToAscii = require('image-to-ascii');
var Download = require('download');
var gif = require('gif-explode')
var fs = require('fs')
exports.getImage = function(url) {
var download = new Download({extract: true, strip: 1, mode: '755'})
.get(url)
.dest(__dirname + "/tmp")
.rename("tmp");
download.run(function(err, files) {
if(err)
throw err;
ImageToAscii(__dirname + "/" + "tmp/tmp", function(err, converted) {
console.log(err || converted);
});
});
}
exports.toAscii = function(cmd) {
var url = cmd.toString().split(' ');
exports.getImage(cmd.toString());
}
exports.gif = function(url) {
var download = new Download({extract: true, strip: 1, mode: '755'})
.get(url)
.dest(__dirname + "/tmp")
.rename("tmp");
download.run(function(err, files) {
if(err)
throw err;
fs.createReadStream(__dirname + '/tmp/tmp')
.pipe(gif(function(frame) {
frame.pipe(fs.createWriteStream(
'frame.gif'
))
ImageToAscii(__dirname + "/" + "frame.gif" , function(err, converted, i) {
console.log(err || converted);
});
}))
});
}