Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (process.argv.length < 3)
- {
- console.log('Usage: node DrawPixelOnConsole.js <image-url> [optional:reverse]');
- return;
- }
- let Jimp = require('jimp');
- let printCharCondition = (x) =>
- process.argv.length >= 4 ? (x < 255 * 0.5 ) : (x > 255 * 0.5);
- let url = process.argv[2];
- Jimp.read(url).then
- (function (image) {
- console.log('\x1b[36m%s\x1b[0m', 'Image size:' + image.bitmap.width + " x " + image.bitmap.height);
- for(let y = 0; y < image.bitmap.height; y++)
- {
- for(let x = 0; x < image.bitmap.width; x++)
- {
- let color = image.getPixelColor(x, y);
- let r = (color & 0xFF000000) >>> 24;
- let g = (color & 0x00FF0000) >>> 16;
- let b = (color & 0x0000FF00) >>> 8;
- //let a = (color & 0x000000FF);
- let illu = 0.2126 * r + 0.7152 * g + 0.0722 * b;
- if (printCharCondition(illu))
- {
- process.stdout.write(' ');
- }
- else
- {
- process.stdout.write('██');
- }
- }
- process.stdout.write('\n');
- }
- },
- function (err)
- {
- console.log(err);
- });
Add Comment
Please, Sign In to add comment