-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasciify-cli.js
55 lines (48 loc) · 1.82 KB
/
asciify-cli.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
55
var asciify = require('asciify-image');
var cli = require('cli');
var detect = require('detect-file-type');
var HeadlessTerminal = require('headless-terminal');
var fs = require('fs');
var PNG = require('pngjs').PNG;
options = cli.parse({
file: ['f', 'Image file to process', 'file', null],
output: ['o', 'Output location including filename', 'file', './output.txt'],
width: ['w', 'Width of output image', 'int', null],
height: ['h', 'Height of output image', 'int', null]
});
var valid_file_types = ['image/jpeg', 'image/png', 'image/gif']
var asciify_options = { fit: 'box', format: 'string' }
if(options.width != null && options.height != null) {
asciify_options.width = options.width;
asciify_options.height = options.height;
} else {
// Default ASCII Width and Height
asciify_options.width = 640;
asciify_options.height = 480;
}
if(options.file != null) {
// Get information about file type.
detect.fromFile(options.file, function(err, file_info) {
if(err) {
return console.log(err);
} else {
if( valid_file_types.includes(file_info.mime) ) {
asciify(options.file, asciify_options, function(asciified) {
// Text output
console.log(asciified)
// Image output using terminal emulation and screen buffer dump
//var terminal = new HeadlessTerminal(asciify_options.width, asciify_options.height)
// Output framebuffer -- Test -- Works
//terminal.write(asciified)
//fs.writeFileSync('output', terminal.displayBuffer.toString());
// Save screen buffer as image Following 3 lines don't work.
//png = PNG.sync.read(terminal.displayBuffer.toString());
//png_buffer = PNG.sync.write(png);
//fs.writeFileSync('out.png', png_buffer);
});
} else {
return console.log("Unsupported File Type. Currently Supported File Types are JPG, PNG, GIF");
}
}
});
}