1

I want to draw human photos on console using nodejs. To draw better quality images I need a library or module that allows me to draw images on console. There certain modules such as imaging and console-png.

However the quality is not that great. How can I draw images probably using HTML5 canvas on console?

Om3ga
  • 24,135
  • 40
  • 122
  • 201

2 Answers2

3

Consoles are text devices, they're not designed for graphics. There are ways of displaying fancy colours etc. in the console but you cannot render an image file or anything there without converting it to text first, like your example, console-png.

Laurel
  • 5,522
  • 11
  • 26
  • 49
Keith
  • 15,057
  • 1
  • 18
  • 31
  • It doesn't matter if it needs to be converted to text first or not. After conversion it should have slightly better quality then currently console-png etc offers. – Om3ga Sep 26 '16 at 19:55
  • I'm not sure you will get much better than what console-png is giving you. Looking at console-png screenshot he is already using half-box glyph to double the horizontal resolution,. In theory he could maybe use more eg. "▄▀ ▀ █ ▌", but remember each glyph is limited to 2 colours (foreground / background). So if 1 character block required more than 2, they would be loss. Another alternative is the ascii-art npm module, but not sure this looks any better than console-png. – Keith Sep 27 '16 at 10:54
3

Please note that this answer is for console (Not the node.js CMD prompt). As this question's title will direct some here that may be using NW.js or similar, allowing node.js console output to be to the V8 dev tools console. There are also some Github solutions that allow console to be directed to V8 dev tools for node.js.

There is also new debugging tools via Chrome Canary lets you debug your browser JavaScript files and Node.js ones in the same DevTools window in parallel.

For Chrome use the console style string directive "%c" in the "console.log" in the first string argument to specify a style.

eg

console.log("%c Blue text","background:blue;"); 

The second argument becomes the` style.

So the logical extension to that is to add a background image and what do you know, it works.

document.body.innerHTML += "For Chrome users hit F12 to open the console. and see it work."
console.log("%c Smile                  .","font-size:28px;color:red;background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAEaElEQVRYhcVXT0iUWxT/fc7ogIsW0UYdx7I2Iq8ZihauhoSoEEJNEBGkneNCUrCBSpudb1GSIEiL3IguBHUUDcL+ODoMjyAwkJT3XomL2liO4BCVVr8W5/tz5/tmxqnXe+/AWXz3nvs7v+/cc889F8hfCgE0AvgdwGMAWzZ9rM816ra/TCoA9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SqUZQAsK/v4Fzo67Psu7qc89kuI8d1rGpTkwXq84HXrkmSvnolOjsrY0r7xbt3nTi5rmMgQ0Oi6pkzcp6zZbqhVVVgNOpcf1BDYoijJVO1rk5IaJokH5TLqKwsd+dstGQuF/7I5hwASvXGkeXlUuUykSguFnW7RTMlqPrnRlPqcuFvHNCUAnm05f390gdeuZJeYu36M225If/rw0SViALynz7NVKnADz5ONQ07+EWPU1X+lef5dx3fisFC3wKhAAAAAElFTkSuQmCC');");

And you have an image. As node.js is V8 then this should be the solution you are after, with a bit of extra styling to make it more image like than background like.

So to do from a canvas just use canvas.toDataURL to get the background URL

And according to this 4year old answer it also works on Firefox.. but not for me and I am sure someone that can make Edge run without overheating their GPU and shutting down their machine will tell you if it works on Edge. |:P

Community
  • 1
  • 1
Blindman67
  • 41,565
  • 7
  • 47
  • 102
  • 1
    I meant terminal not chrome console. – Om3ga Sep 26 '16 at 19:56
  • 1
    @2619 Sorry console to me means dev.tools, though terminal is something else as well so I think you mean CMD prompt. A quick look with google and there is a host of node.js CMD line prompt alternatives, or create your own that can accept a image stream (raw pixel stream is easiest) – Blindman67 Sep 26 '16 at 20:36
  • more complex way to output your base64 or image from URL (to devtools): `console.log("%c ",`font-size:50px; background:url('${ base64imageString_orImageURL_here }') center / 100% 100%;`);` – flashTGC Jan 25 '18 at 12:08