Color Ascii Art

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Color Ascii Art

#1 Post by Aacini » 24 Dec 2012 13:59

Image

EDIT: I don't understand what happens. In Preview mode previous image appear, but when I posted the topic it does NOT appear!. This is the address of the image: http://i.imgur.com/RFAS2.jpg


This topic started at this request: [t=4018&p=22321#p22321]
Boombox wrote:.
Thanks all. But I'm still struggling.

I have a text file containing colour codes.

a=44
b=17
c=29
d=4f

etc.

And a text file containing simple ascii art.

How can I compare the two files and print the ascii art to the command window with the colours I specify?
I posted my solution and asked Boombox for their Ascii-Art and color-codes files, but he had not answered yet... I remember the Ascii-Art I saw back in the 70's created with multi-striked characters that produce a wide range of grey levels and printed in several pages of Z-fold paper to create giant posters. I wanted to do a similar thing, but in color and just into the MS-DOS Window. For simplicity, I wanted to use the method stated by Boombox: assign a color-code to each character in the Ascii-Art file.

Then I saw this dbenham's post: [http://ss64.org/viewtopic.php?pid=6336#p6336] in SS64 forum about "coloured" Ascii-Art; however, those images show a same character in several different colors and not use levels/shades of color, so it is not what I wanted.

I searched the web for an Image-to-Ascii Art conversion program. After a short search, I got Ascii Generator 2. I have not time to do extensive searching and testing, so I don't know if there are better programs around.

Before start the conversion process, I needed to know the resolution I will use in my images (I wanted the largest possible one), so I created a copy of the short-cut icon of MS-DOS, right-click on it and selected: Properties, Font tab and the smallest True-Type font: Lucida Console @ size 5; then Layout tab and the largest Width and Height for buffer and window size that not require scroll bars: 341x139. Ok.

I copied the Mona-Lisa.jpg image from: [http://alfdelvalle.blogspot.mx/2011/01/el-codigo-mona-lisa.html]. I started Ascgen2 and selected Font... Lucida Console @ size 5. Ok. I loaded the Mona Lisa image and checked the default size: 150x64. I tried to set 340x138, but when Lock Aspect Ratio is set just Width or Height can be changed, so I set H=138 and get 322x138. I saved the result to a disk file. Then I double-clicked on the new MS-DOS icon and executed: "COLOR F0" for black text on white background and "TYPE ASCII-MONA-LISA.TXT", and my first black&white Ascii-Art image appeared in the screen!

To define color codes for the characters in the Ascii-Art file I completed these (long!) steps:

1- Find out which characters can be used as part of variable names in my ShowColorAsciiArt.bat program. For Ascii characters 32-127 the following can not be used: exclamation-point, semicolon, equal-sign and caret. Batch variable names are not case sensitive, so I also excluded one size of each letter. Besides, Ascgen2 don't use certain characters, so I must further adjusted the set. I got different results in succesive Ascgen2 executions until I set Dither=0 in text settings sub-window. This is the final 64 characters set I used:

Code: Select all

set ^"Characters= "#$%&'()*+,-./0123456789:<>?@ABCDEFGHIJKLMNoPQrStUvWXYZ[\]_`{}~^"
This way, I had 64 characters to represent different colors, so I needed a method to assign color codes to each of them.

To summarize the conversion of image to text: start Ascgen2, load the image and:
- In Font... select: Lucida Console and enter size=5. Ok
- Set Characters to: "#$%&'()*+,-./0123456789:<>?@ABCDEFGHIJKLMNoPQrStUvWXYZ[\]_`{}~
(don't forget the initial space)
- In Size: select right side and enter: 138
- In text settings (bottom left sub-window) select Dither=0
Now you can Save the output file As Black&White Text.

2- I copied an image of the standard EGA 64-colors palette from: [http://commons.wikimedia.org/wiki/File:EGA64_Full_Palette.png], converted it with Ascgen2 using previous settings and used the output as guideline to assign color codes. In black&white conversion, each character have a certain number of black pixels that generate different levels of grey when it is displayed on the white background cell. In this color conversion, those different levels per character are taken from one of 16 possible foreground colors over 16 possible background colors. This generate a wide range of color shades (theoretically 64*16*16) that made harder the assignment of individual color-codes per character. I first set colors that have an unique character, but there are few; for the rest of characters I must individually adjusted color codes until output image visually matched as best as possible the colors of input image. After some testing, I finally got this table (unassigned characters have 08 color code):

Code: Select all

 =FF= White,         Standard text color F, EGA 63
"=BB= Light Cyan,    Standard text color B, EGA 59
#=08
$=08
%=3D= 13- Testing... (light magenta on cyan)
&=00= Black,         Standard text color 0, EGA 0
'=08
(=08
)=08
*=AA= Light Green,   Standard text color A, EGA 58
+=7B= 10- Testing... (light cyan on grey)
,=08
-=FB= 6- Testing...  (light cyan on white)
.=EE= Yellow,        Standard text color E, EGA 62
/=08
0=08
1=08
2=08
3=33= Cyan,          Standard text color 3, EGA 3
4=15= 12- Testing... (magenta on blue)
5=35= 11- Testing... (magenta on cyan)
6=08
7=08
8=31= 8- Testing...  (blue on cyan)
9=66= 4- Testing...  (brown)
:=EF= 2- Testing...  (white on yellow)
<=08
>=08
?=08
@=33= 5- Testing...  (cyan)
A=DD= 3- Testing...  (light magenta)
B=44= Red,           Standard text color 4, EGA 4
C=08
D=55= Magenta,       Standard text color 5, EGA 5
E=88= Grey,          Standard text color 8, EGA 56
F=08
G=08
H=08
I=22= Green,         Standard text color 2, EGA 2;  COLLISION with color 9
J=3A= 15- Testing... (Light green on cyan: good in two, bad in one...)
K=08
L=DD= Light Magenta, Standard text color D, EGA 61; COLLISION with color 6
M=11= Blue,          Standard text color 1, EGA 1
N=08
o=08
P=08
Q=08
r=08
S=2C= 14- Testing... (light red on green: one good, one bad...)
t=08
U=08
v=CC= Light Red,     Standard text color C, EGA 60
W=08
X=08
Y=08
Z=08
[=08
\=77= White,         Standard text color 7, EGA 7
]=08
_=08
`=FE= 1- Testing...  (little yellow on white)
{=6E= 9- Testing...  (yellow on brown)
}=08
~=FA= 7- Testing...  (light green on white)

There is no way to achieve a perfect color match because a same character is used in several levels of grey; this cause that the same color be used in several different image colors. The best possible color conversion for Ascii-Art printed this way could be obtained if Ascgen2's author, Jonathan Mathews, could modify its program in order to directly use levels of foreground color over background color per character, and also generate the color-codes table. With current Ascgen2 program, a good color conversion start with the font and characters used by Ascgen2 and particularly with Dither value that cause that colors be created by groups of characters, and continue with extensive testing and adjustment of the color codes assigned to each character. However, I have not time to do extensive tests, so I just defined a second color-codes table; if someone define a better one, please post it.

Code: Select all

 =FF=   ColorCodes.txt file for ColorAsciiArt.bat conversion to .CAA file
"=BB=   Antonio Perez Ayala
#=08
$=08=   Use this file with Dither=4 value in Ascgen2 text settings sub-window
%=22
&=00
'=08
(=08
)=08
*=AA
+=AA
,=08
-=EE
.=EE
/=08
0=08
1=08
2=08
3=33
4=88
5=44
6=88
7=08
8=44
9=55
:=EE
<=08
>=08
?=77
@=55
A=AA
B=55
C=08
D=55
E=88
F=08
G=08
H=08
I=22
J=66
K=08
L=66
M=11
N=08
o=08
P=08
Q=08
r=08
S=33
t=08
U=08
v=DD
W=08
X=33
Y=08
Z=08
[=08
\=77
]=08
_=08
`=FF
{=66
}=08
~=BB

I also modified my former solution to made it faster. I divided my original program in two parts: the first one convert the Ascii-Art.txt file into a new type of file with .CAA extension that contain the parameters required by my ColorShow.exe auxiliary program (seek for program #12 at that site).

Code: Select all

@echo off

rem ColorAsciiArt.bat: Convert an Ascii-Art.txt file created by Ascgen2 to .CAA file
rem Ascgen2: http://sourceforge.net/projects/Ascgen2
rem Antonio Perez Ayala

setlocal DisableDelayedExpansion
set Ascii= !"#$%%&'()*+,-./0123456789:;<_>?@ABCDEFGHIJKLMN_PQ_S_U_WXYZ[\]^_`~~~~~~~~~~~~~~o~~r~t~v~~~~{|}~
setlocal EnableDelayedExpansion

rem Create special Ascii character table (not equal-sign, just one letter/size)
for /L %%i in (0,1,94) do (
   set /A code=%%i+32
   set ascii!Ascii:~%%i,1!=!code!
)

rem Load ColorCodes.txt file: char=color= Optional comments
for /F "tokens=1,2 delims==" %%a in (ColorCodes.txt) do (
   set "color%%a=%%b"
)

rem Get file name
set inFile=%~1
set outFile=%~N1.caa
if not defined inFile (
   set inFile=ASCII-EGA64_Full_Palette.txt
   set outFile=ASCII-EGA64_Full_Palette.caa
)

rem Convert the file
echo Converting file "%inFile%" to Color Ascii-Art .CAA file...
del temp.tmp 2>NUL
set height=0
set width=
for /F "usebackq delims=" %%a in ("%inFile%") do (
   set "inLine=%%a"
   set /A height+=1
   if not defined width (
      rem Get width of input line
      set width=0
      for /L %%a in (12,-1,0) do (
         set /A "width|=1<<%%a"
         for %%b in (!width!) do if "!inLine:~%%b,1!" equ "" set /A "width&=~1<<%%a"
      )
      set /A width+=1
   )
   set Char=
   set Count=0
   set outLine=
   for /L %%b in (0,1,!width!) do for /F "delims=" %%c in ("!inLine:~%%b,1!") do (
      if "!Char!" neq "%%c" (
         if !Count! gtr 1 (set Count=*!Count!) else set Count=
         if "!Char!" neq "" set outLine=!outLine! /!Color! !Ascii!!Count!
         set "Char=%%c"
         set "Ascii=!ascii%%c!"
         set "Color=!color%%c!"
         set Count=1
      ) else (
         set /A Count+=1
      )
   )
   if !Count! gtr 1 (set Count=*!Count!) else set Count=
   set outLine=!outLine! /!Color! !Ascii!!Count!
   echo !outLine! >> temp.tmp
   set /P "=." <NUL
)
echo/
echo %height% %width%> "%outFile%"
type temp.tmp >> "%outFile%"
del temp.tmp
The second program read the Color Ascii-Art .CAA file and show the image in the screen.

Code: Select all

@echo off

rem ShowColorAsciiArt.bat: Show a .CAA file created by ColorAsciiArt.bat
rem Antonio Perez Ayala

setlocal EnableDelayedExpansion

set myPath=%~DP0
set filename=%~DPN1
if defined filename (
   title MS-DOS - ShowColorAsciiArt.bat  %~NX1
) else (
   set filename=%myPath%ASCII-EGA64_Full_Palette
)

set lines=
for /F "usebackq delims=" %%a in ("%filename%.caa") do (
   if not defined lines (
      for /F "tokens=1,2" %%b in ("%%a") do set /A lines=%%b+1, cols=%%c+1
      mode con cols=!cols! lines=!lines!
   ) else (
      "%myPath%ColorShow" %%a
      echo/
   )
)
set /P =
Previous program took less than 3 seconds to show the image of Mona-Lisa shown at beginning of this topic. That image was converted using the first ColorCodes.txt table.

You may use the new MS-DOS short-cut in an easier way if you add to its Target line the /C switch, a double quote and the full path to ShowColorAsciiArt.bat file ending in one quote; for example:

Code: Select all

%SystemRoot%\system32\cmd.exe /C ""%UserProfile%\My Documents\Color Ascii Art\ShowColorAsciiArt.bat"
This way, to show a .CAA image file just drag and drop it on the MS-DOS icon.

Merry Christmas! :D

Antonio

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Color Ascii Art

#2 Post by Ed Dyreen » 24 Dec 2012 14:07

Aacini wrote:EDIT: I don't understand what happens. In Preview mode previous image appear, but when I posted the topic it does NOT appear!. This is the address of the image: http://i.imgur.com/RFAS2.jpg
It appears just fine over here, this could be something with your browser cache, it has happend to me too.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Color Ascii Art

#3 Post by batchcc » 25 Aug 2015 06:09

dear Aacini I really like your batch Mona Lisa is there anywhere I could download it thanks

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Color Ascii Art

#4 Post by ShadowThief » 25 Aug 2015 06:14

batchcc wrote:dear Aacini I really like your batch Mona Lisa is there anywhere I could download it thanks

Right-click -> Save Image As...

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Color Ascii Art

#5 Post by batchcc » 25 Aug 2015 06:15

the batch file

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Color Ascii Art

#6 Post by Squashman » 25 Aug 2015 07:36

batchcc wrote:the batch file

It is all in his post with the picture.

lylalandry
Posts: 1
Joined: 27 Apr 2019 03:23

Re: Color Ascii Art

#7 Post by lylalandry » 27 Apr 2019 03:25

How you convert image to ascii?

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Color Ascii Art

#8 Post by Aacini » 27 Apr 2019 06:28

@lylalandry, I clearly explained the process in my post... Can't you see the same paragraphs I wrote? :?

Aacini wrote:
24 Dec 2012 13:59
.....

I searched the web for an Image-to-Ascii Art conversion program. After a short search, I got Ascii Generator 2. I have not time to do extensive searching and testing, so I don't know if there are better programs around.

.....

I copied the Mona-Lisa.jpg image from: [http://alfdelvalle.blogspot.mx/2011/01/el-codigo-mona-lisa.html]. I started Ascgen2 and selected Font... Lucida Console @ size 5. Ok. I loaded the Mona Lisa image and checked the default size: 150x64. I tried to set 340x138, but when Lock Aspect Ratio is set just Width or Height can be changed, so I set H=138 and get 322x138. I saved the result to a disk file. Then I double-clicked on the new MS-DOS icon and executed: "COLOR F0" for black text on white background and "TYPE ASCII-MONA-LISA.TXT", and my first black&white Ascii-Art image appeared in the screen!

.....

Antonio

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Color Ascii Art

#9 Post by Squashman » 27 Apr 2019 20:40

lylalandry wrote:
27 Apr 2019 03:25
How you convert image to ascii?
Reading is fun.

Post Reply