daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Feb 15th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (process.argv.length < 3)
  2. {
  3.     console.log('Usage: node DrawPixelOnConsole.js <image-url> [optional:reverse]');
  4.     return;
  5. }
  6.  
  7. let Jimp = require('jimp');
  8.  
  9. let printCharCondition = (x) =>
  10.     process.argv.length >= 4 ? (x < 255 * 0.5 ) : (x > 255 * 0.5);
  11.  
  12. let url = process.argv[2];
  13. Jimp.read(url).then
  14. (function (image) {
  15.     console.log('\x1b[36m%s\x1b[0m', 'Image size:' + image.bitmap.width + " x " + image.bitmap.height);  
  16.  
  17.     for(let y = 0; y < image.bitmap.height; y++)
  18.     {
  19.         for(let x = 0; x < image.bitmap.width; x++)
  20.         {
  21.             let color = image.getPixelColor(x, y);
  22.  
  23.             let r = (color & 0xFF000000) >>> 24;
  24.             let g = (color & 0x00FF0000) >>> 16;
  25.             let b = (color & 0x0000FF00) >>> 8;
  26.             //let a = (color & 0x000000FF);
  27.             let illu = 0.2126 * r + 0.7152 * g + 0.0722 * b;
  28.  
  29.             if (printCharCondition(illu))
  30.             {
  31.                 process.stdout.write('  ');
  32.             }
  33.             else
  34.             {
  35.                 process.stdout.write('██');
  36.             }
  37.         }
  38.         process.stdout.write('\n');
  39.     }
  40. },
  41. function (err)
  42. {
  43.     console.log(err);
  44. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top