Is there any sort of utility I can use to convert an image to ASCII and then print it in my terminal? I looked for one but couldn't seem to find any.
A program called cacaview allows you to do this.
It is interactive, allowing you to pan, zoom, and change display modes.
more simply, you may use img2txt
from the caca library (cacaview
is an image browser and opens a new window, which is not what is asked here I guess);
For instance :
$ img2txt /Users/foo/pool/libs/ipython/docs/resources/ipynb_icon_256x256.png
.:.:.:.:.:.:.:.:.:.:.:tS@8
. . . . . . . . . . . . ..:;@@t%;;X
. . . . . . . . . . . . . . .X8S%%8%.8
. . . . . . . . . . . . . . . ..8Xttt%S8.
. . .. . . . . . . . . . . . . .8;%88888S
. . . . . . . . . . . . . . . . ..8X. . .t
.tS%SSS X . :SXS@8:@. . . . . . . .. . . . t
. .%:S . .@;XX8@@:; .X8%t@ . . .@tX8S . .;
. . t;@ . . @SS. .S;8 @@. .:8. %%S.8@X 8X8t
. . %tX . . @S8 .@@t...@8: .X:;.tX..8.:.@%tt
. . ttX. . .8tt;t.@t .8: . @8X.X .%88... t
. . %tX . . @S@::. . . 88 ...; X% . 88:.S8;t
. . ttX . . @X8 . . . .88 . :.;. .88S.%88t
.t88 ; 88. .8SS. . . ..88.%8.@ 8. 8X88;. .;
. S%SStSS. .;S.. . . ..:%XX:;; . .;X%;... t
. . . . . . . . . . . @XX8;.. . . . . . t
. ;@XXX t. .. . .S88%. % %@. . . .. . . . t
. %8888@Xt. . . S888 . 888:. . . . . . . t
. S888888 ;. . . .. 8@:.: 88 . . . . . .;
. %888%888 . . S888.:8%88: X8%tS8t.. . .;
. S888.X888;. . .. @8@ :;.88888@8X8X8S8. . t
. :8.X% 8888%.. ..S88@.:8S8t88.%88X@t88%. .;
..S8@8t..8:88t. ..% 88t ;88@8;:.... 88888..t
. S888S : .8@8X. .;88X..%:888. .. 888. t
. t8:XS. ..:888;..@888..: 88 .. . .888X:.;
. X888; . . ;:8@t.S:88:.@S88t. . . . %88:8.t
. %8 8S. .. 8888; @8S..:888 . . .8888 t
. %888;. .. 888SX;@8:.;8888 . . ..8S88:.;
. S@888;. . :8:88888;.t8888S.. . :X8888: t
. %88 X . . ...:888888;.;88888:tXSS8888t.. t
. %888@. . . SX88X8: S888@S888888%88. . t
. tt.. . . .. .::t:t .:.%S. X8%X8;: . . t
. . . . . . . .... . ..... ....: . . . t
%8@8@8@8@8@8@8@@8@8@8@8X8X88S8X8X8X8X8X8X8XX
$
on macosx, you may use homebrew :
$ brew reinstall libcaca --with-imlib2
(imlib is used to convert from different formats)
Here's a utility that does this (with source code):
http://www.codeproject.com/Articles/10949/ASCII-Art-Generator
A high quality fast standalone conversion utility (provided you have a 256 color terminal) is pxl
, available at https://github.com/ichinaski/pxl.
Another alternative is to use the Ipython notebook: it is pretty good at doing what you ask for.
For bash: You have to prepend commands with a bang. For images: You may use the rich display system from ipython.
A screenshot of the result:
Complete answer in this post.
来源:https://stackoverflow.com/questions/12233105/how-can-i-display-an-image-in-the-terminal