简体   繁体   English

在控制台上绘制HTML5画布

[英]Draw HTML5 canvas on console

I want to draw human photos on console using nodejs. 我想使用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 . 有某些模块,例如Imagingconsole-png

However the quality is not that great. 但是质量不是那么好。 How can I draw images probably using HTML5 canvas on console? 如何在控制台上使用HTML5 canvas绘制图像?

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. 有多种方法可以在控制台中显示奇特的颜色等,但是您不能在不首先将其转换为文本的情况下渲染图像文件或其中的任何内容,例如您的示例console-png。

Please note that this answer is for console (Not the node.js CMD prompt). 请注意,此答案是针对控制台的(不是node.js CMD提示)。 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. 因为这个问题的标题将一些可能使用NW.js或类似内容的内容引到这里,从而允许将node.js控制台输出到V8开发工具控制台。 There are also some Github solutions that allow console to be directed to V8 dev tools for node.js. 还有一些Github解决方案,可将控制台定向到用于node.js的V8开发工具。

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. Chrome Canary还提供了新的调试工具, 可让您在同一DevTools窗口中并行调试浏览器的JavaScript文件和 Node.js。

For Chrome use the console style string directive "%c" in the "console.log" in the first string argument to specify a style. 对于Chrome,请在第一个字符串参数的“ console.log”中使用控制台样式字符串指令“%c”来指定样式。

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,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAY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z4Nvn6d30WkkrBrZ2e6rT0JHceQBEdGxMjnA79+TZ/79g0cHATHx8FHj6ztu3FDtq2yEjx1CjxyBOzvl8tKXW8/ho5CZGgwKIY3bzoJXL4siVpYCIbDzrW7u+DeHvjpk3POXoigl0WzFBv69KkVxpERJ9Dbt+CtW+D6evr4mzcSlfFxMB5Pn8tUigHbZaSqUZQAsK/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. 由于node.js是V8,因此这应该是您所追求的解决方案,并带有一些额外的样式,使其比背景图像更具图像感。

So to do from a canvas just use canvas.toDataURL to get the background URL 因此要在画布上执行操作,只需使用canvas.toDataURL来获取背景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. 并且根据这个已有4年历史的答案,它也可以在Firefox上运行。.但是对我而言,这不是。我确信可以使Edge运行而不会导致GPU过热并关闭其计算机的人会告诉您它是否可以在Edge上运行。 |:P |:P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM