Jamyy's Weblog

Linux 環境下的 ASCII 轉檔

by Jamyy on 八月.11, 2006, under Linux

  • 文字轉圖檔
  • 文字檔轉圖檔
  • 圖檔轉文字檔 (ASCII Art)

文字轉圖檔

需求套件: enscriptImageMagick

ImageMagick 5.5.6-5

echo 'Hello, World!' | enscript -B -f "Palatino-Bold48" -o - | convert -crop 0x0 - output.png

ImageMagick 6.2.2.0-2.fc3

echo 'Hello, World!' | enscript -B -f "Palatino-Bold48" -o - | convert -trim - output.png

輸出結果:

預設可使用的字型:

產生以上圖檔的 Shell Script:

#!/bin/bash

for i in `cut -f 1 /usr/share/enscript/font.map`
do
echo "$i" | enscript -B -f "`echo $i`24" -o - | convert -negate -trim - "$i.png"
done

文字檔轉圖檔

需求套件: enscripta2ps

操作指令:

enscript myfile.txt -f "Courier12" -B -o - | convert -trim - output.png

a2ps -B --borders no -1 -o - myfile.txt | convert -trim - output.png

輸出結果:

圖檔轉文字檔 (ASCII Arts)

需求套件: aview

操作指令:

asciiview myimage.jpg

常用按鍵:

h = help; s = save; q = quit

原圖:

輸出結果:

			              _             ,
			      _      |]             b,     :.
			     _#     |W-             4b;     #,
			    |0]    j#D              j#&i    3k;
			   .j0:   |4#k              |406,   ]0L,
			   j#R   .j00f    jW000&,   :40#l    0#i
			  :d#O   :4001   x#000000_  .d#0T    00k,
			  |40]   |W001   #0000000X  .d#0k    W0A)
			  |W0]   |W001   Q00000003  :d#0k    W0Wi
			  |W0W   -4W0k    4#000#~   |W0#[   .00Wi
			  |400g_..:4#0myygmW000WggyyW0#T..._W008<
			   "***H*H9999*R00000000000X*9!9999**97'
			       ._ajyWW000000000000000#Wmya_,
			_aaaam#000##P!H#0000000000009!400#000maaaa.
			#0##@9"-g0#1  X0000000000000: -4#0x-"*#0##g
			N00F`   00Wi  X0000000000000;  j#0O   |4003
			4#0A;   O0Wi  ]0000000000000` .j#0]   |W00-
			?40#1   ~#01. -#00000000000H  :d0H-  .J00F
			 ?40&    40Ai  +0000000000#-  jW#-   j#0F'
			  "40_   -401,  !#0000000R"  _j#f    d#P'
			   -4#,   -4&i   -N00#00*    jWf`   |#f`
			    -*m.   -?6    -?!!!^    |J{`   _#{`
			      *g     ?              /'    .W"
			       "|                         ]-

參考資料:

相關網頁:



: