如何将图形图像转换为 ASCII 艺术?

如何将图形图像转换为 ASCII 艺术?

我想要一个由字符组成的终端自定义图像,有没有什么程序可以使用?

具体来说,我学校的机器人设备 标识

答案1

您可以尝试一个应用程序,jp2a用于在终端窗口将 jpg 转换为 ascii。

sudo apt update
sudo apt install jp2a

然后运行jp2a filename.jpg

~$ jp2a 1Fy7Yz2.jpg 

.dKKKKKl.....dKK000000OOOOkkkxxxxddoooooolloddxxxkO00k....................
'0KKKK0..'...oKKK000000OOOOOkkxxxdddooooollodxxxxkO00O....................
dKKKK0,....'.:KKKKK0000000OOOOkkxxxddddoooooxxxxkOO00O'...................
0KXK0.  ........'',,,,,;;;;;;;;;;;,,,'''''.''''....'';;...................
O0O0o............                                 ...'l...................
0K0kkkxxxdol:.    .,:;;.....           .   ... .   .......................
d000kkOKKKKKKk.  .dO000klooc;... .  .':::ccood;... c,.....................
..oOkdx0KKK0KKx.  ,,od.l'xdl.  ':ldkkkkxxdxO0KXo.  cc.....................
. :kxodk00O;0K0k,   'l,,.;;cok00OOkxxxkkxxxk0Kkkk:,,k.....................
..lxdookkOl.'OKKOd;,;coxO0000OkdoodkOOOkxddk0KkodOxdk.....................
loldccdxkk....oKKK00KK0OkxdolodkOO000OOkxddk00koddxkl.....................
dd,;coddxx'.....oxxddollodxkkOOOOOOOOOkkxddk000loO0d......................
::ldxxooodd,...;kxxxkkkkkkkkkkkOOOOOOOko:'...'oloxKo......................
olcldOOxolloo;,kkOOOkkkkkkkkkkkkOOko;.      .. ,cdkx;.....................
l:ccl:odOkdccloxkkkkkkkkkkkkkkkxc.      ..'',;.''odOd:....................
dxl::::;clkkxlccodxxkkkkxxxxd:.  .':ldxkxdddxkOl.;dxld,...................
odddl:;;;;:cxkkdlcloddddol:,';coxxxkkkkxxdddxkOdllxkoll...................
clooddc;;;;;;okkkxdllloodddddxxxxxxkkkkxxdodxkkkllkOkk:...................
:cclloddc:,oxxxxdddoodddddddddxxxxxkkkxxxdoodxkOooxxkk:...................
;;:cclloodoollllloodddddoodddddddxxxxxxxdooldxkOoOxddxxc..................
.',;::ccccccccllloooddddddoooooodddxxxxo:,'',;:ddkdooodd:.................
  .',;;::cccllllllooooooodddoooooodddo;..   ...'okollllod.................
   .,':::ccclllllllloooooooodollooooo;.   . ....cxlcclllo;................

--background=light或者如果你的终端有浅色背景你也可以使用:

~$ jp2a 1Fy7Yz2.jpg --background=light

K:.....l0000K:........'''',,,;;;;::ccccccllc::;;;,'..,0000000KKKKKKKKKKKKK
O......00O00Kc.........''''',,;;;:::cccccllc:;;;;,'..'0000000KKKKKKKKKKKKK
:.....kK000O0d............'''',,;;;::::ccccc;;;;,''..'O000000KKKKKKKKKKKKK
.....KMNXXXXXX00OOkkkkkxxxxxxxxxxxkkkOOOOO0OOOO0000OOxxKKKK0KKKKKKKKKKKKKK
'.'.cKK0KKXXXXXXXNNNWWWWWWWWWMMMMMMMMMMMMMMMWNNNNNXXKOl0KKKKKKKKKKKKKKKKKK
...,,,;;;:cld0MMWW0kdxxKKXKXNNWWWWMMMMMXNNWK0XWXNNNKKKKKKKKKKKKKKKKKKKKKKK
:...,,'......,KMW0:'...,lccox00XNKWNKOdddoocc:x0X0NokKKKKKKKKKKKKKKKKKKKKK
0Xc',:;.......;XWNkkc:0lO;:lKWNOdl:,,,,;;:;'...cXNNooKKKKKKKKKKKKKKKKKKKKK
KNd,;c:,..'x...,kWNNOlkkKxxoc,..'',;;;,,;;;,..,,,dkk,0KKKKKKKKKKKKKKKKKKKK
0Xl;:cc,,'lXO'..':xkxoc;'....',:cc:,''',;::,..,c:';:,0KKKKKKKKKKKKKKKKKKKK
lcl:oo:;,,0KX0c........',;:clc:,''...'',;::,..,c::;,lKKKKKKKKKKKKKKKKKKKKK
::kxoc::;;OKXXK0c;;::cllc:;,,''''''''',,;::,...lc'.:KKKKKKKKKKKKKKKKKKKKKK
ddl:;;ccc::kKKXx,;;;,,,,,,,,,,,''''''',cdOKKKOclc;.cKKKKKKKKKKKKKKKKXXXXXX
clol:'';cllccxk,,''',,,,,,,,,,,,'',cx0NWMWNNX0Wko:,;xKKKKKKKKKKKKKKKKKKKKK
ldooldc:',:oolc;,,,,,,,,,,,,,,,;o0WNNNNNX0OOkxKOOc:':dKKKKKKKKKKKKKKKKKKKK
:;lddddxol,,;looc:;;,,,,;;;;:d0NNKOdl:;,;:::;,'lKx:;l:kKKKKKKKKKKKKKKKKKKK
c:::ldxxxxdo;,,:lolc::::cldkOxoc;;;,,,,;;:::;,':ll;,cll00KKKKKKKKKKKKKKKKK
olcc::oxxxxxxc,,,;:lllcc:::::;;;;;;,,,,;;:c:;,,,ll,',,d00KKKKKKKKKKKKKKKKK
doollc::odkc;;;;:::cc:::::::::;;;;;,,,;;;:cc:;,'cc;;,,dKKKKKKKXXXXXKKKKKKK
xxdoollcc:cclllllcc:::::cc:::::::;;;;;;;:ccl:;,'c';::;;oKKKXXXXXXXXXKKKKKK
0Okxddoooooooolllccc::::::cccccc:::;;;;cdkOOkxd::,:ccc::dXXXXXXXXXXXXXXXXX
WW0Okxxddooollllllccccccc:::cccccc:::cxXXNNNXK0Oc,cllllc:0XXXXXXXXXXXXXXXX
NWWKkOdddooollllllllcccccccc:cllcccccxKWNWKWX0K0o;loolllcxXXXXXXXXXXXXXXXX

它在终端窗口中的样子如下:

在此处输入图片描述

希望这可以帮助!

答案2

此处厚颜无耻地插播一句,不过你可以使用我的 cli 工具ascii-image-converter。它可在 snap 上获取:

sudo snap install ascii-image-converter

或者,如果您直接想要二进制文件或其他东西,您可以访问 repo:https://github.com/TheZoraiz/ascii-image-converter#installation

与 不同jp2a,此工具支持 jpeg、png、webp、bmp 和 tiff 图像格式,因此它可以处理您遇到的大多数图像。您可以使用一组标志自定义输出。还有一个选项可以直接将 ascii 图像保存为 png,以节省您截屏的麻烦。上面的 repo 链接提供了更多文档。

作为命令行工具,它仍然相对不成熟,没有大量的标志和选项,但我正在努力改进它并集成新功能。试试看!:)

相关内容