Original Usenet thread from alt.ascii-art, started 9 Oct 2006.
img->ascii
alt.ascii-art
· 9 messages · 9 Oct 2006 - 21 Oct 2006
Hi Has anyone tried Characterizer? it automatically converts images to text: http://aolej.com/free.html#Chara 3Dimka ;) -- Posted via a free Usenet account from http://www.teranews.com
* 3Dimka wrote: > Hi > Has anyone tried Characterizer? > it automatically converts images to text: > http://aolej.com/free.html#Chara Do you know of an equivalent for linux? -- Troy Piggins
Troy Piggins wrote: > * 3Dimka wrote: >> Hi >> Has anyone tried Characterizer? >> it automatically converts images to text: >> http://aolej.com/free.html#Chara > > Do you know of an equivalent for linux? JavE is a java program .. it should run on linux too. http://Jave.de
In alt.ascii-art, Troy Piggins <use...@piggo.com> wrote: > * 3Dimka wrote: > > Has anyone tried Characterizer? > > it automatically converts images to text: > > http://aolej.com/free.html#Chara > Do you know of an equivalent for linux? Get the PBM Tools (or Netpbm) package and use pbmtoascii (comes with the package) or hunt the Google archives for my pgmtoascii script. Actually, now I have a colorizer that I use with it, too. Example usage: djpeg IMAGE.jpg > IMAGE.ppm pnmscale -yscale 0.25 -xscale 0.5 IMAGE.ppm > IMAGE-scaled.ppm ppmtopgm IMAGE-scaled.ppm > IMAGE-scaled.pgm # sometimes a pnminvert of the pgm file will help a lot pgmtoascii IMAGE-scaled.pgm > IMAGE-scaled.txt colorizeascii IMAGE-scaled.txt IMAGE-scaled.ppm > IMAGE-scaled.html Look for the colorizer at the end of this post. Elijah ------ #!/usr/bin/perl -w # Take a PPM file and a text file and create an html file with colorized # text based on the PPM colors. The text file should have at least as # many characters as the PPM file has pixels. # Output is html, either HTML 3.2 with <font color> tags or HTML 4 # with a stylesheet and <span class> tags. A background color can be # specified. # # 6 April 2006 B. Elijah Griffin Eli the Bearded use strict; use vars qw( $ppmin $textin $mode $bgcolor $body $css $char $color $title $id $w $h $p $ppm_r $p_r $text %colors @pixels $lastcolor $rc $pc $cc $cssc $fontsize ); use Image::PBMlib; $id = $0; $id =~ s:.*/::; $title = 'image'; $bgcolor = 'white'; $body = $css = ''; $mode = 'css'; while (defined($ARGV[0]) and $ARGV[0] =~ /^-(.*)/) { my $arg = $1; shift; if ($arg eq '-help' or $arg eq '-version' or $arg eq 'v') { &usage(0); } elsif ($arg eq 'h' or $arg eq '-html') { $mode = 'html'; } elsif ($arg eq 'c' or $arg eq '-css') { $mode = 'css'; } elsif ($arg eq 'b' or $arg eq '-bgcolor') { $bgcolor = shift; } elsif ($arg eq 't' or $arg eq '-title') { $title = shift; } elsif ($arg eq 'f' or $arg eq '-fontsize') { $fontsize = shift; } else { die "$id: unrecognized option: -$arg\n"; } } $textin = shift; $ppmin = shift; if (!defined($textin) or !defined($ppmin)) { die "$id: need two input files: textin ppmin\n"; } if (!(-f $textin) or !(-f $ppmin)) { die "$id: one or more input file does not exist\n"; } if(!open(PPM, "< $ppmin")) { die "$id: can't open ppm file $ppmin: $!\n"; } if(!open(TEXT, "< $textin")) { die "$id: can't open text file $textin: $!\n"; } $ppm_r = readppmheader(\*PPM); if(defined($$ppm_r{error})) { die "$id: ppm error $ppmin: $$ppm_r{error}\n"; } if($$ppm_r{bgp} ne 'p') { die "$id: ppm error $ppmin: not a pixmap\n"; } $w = $$ppm_r{width}; $h = $$ppm_r{height}; $p = ($w * $h); @pixels = readpixels_raw(\*PPM, $$ppm_r{type}, $p); { local $/ = undef; $text = <TEXT>; } $text =~ tr:\cJ\cM::d; if($p > length($text)) { die "$id: text error $textin: not enough characters\n"; } close TEXT; close PPM; $cc = $pc = $rc = 0; while($p_r = shift(@pixels)) { # Grab the first character, and replace it with the empty string $char = substr($text, 0, 1, ''); # Don't color spaces if($char !~ /\s/) { $color = sprintf("%02x%02x%02x", ord($$p_r[0]), ord($$p_r[1]), ord($$p_r[2])); if(defined($lastcolor)) { if ($color ne $lastcolor) { &endcolor(); &startcolor($color); } } else { &startcolor($color); } if ($char =~ /<>&/) { $char =~ s/&/&/; $char =~ s/</</; $char =~ s/>/>/; } } $body .= $char; $pc ++; $rc ++; if($rc == $w) { $body .= "\n"; $rc = 0; } } &endcolor(); print <<"HTMLheader"; <html> <head> <title>$title</title> HTMLheader if($mode eq 'css') { if(defined($fontsize)) { $fontsize = " font-size: $fontsize"; } else { $fontsize = ''; } print <<"CSSheader"; <style type=text/css><!-- H1 { font-weight: bold; font-size: 18px } Pre { background-color: $bgcolor; border: 1px gray; font-family: courier,monospace; padding: 0px 5px 20px 5px; margin: 10px 5px 10px 15px;$fontsize } $css --></style> </head> <body> CSSheader } else { print <<"BODYheader"; </head> <body bgcolor="$bgcolor"> BODYheader } print <<"FINISHpage"; <h1>$title</h1> <pre>$body</pre> </body> </html> FINISHpage exit(0); sub startcolor($) { $lastcolor = shift; if($mode eq 'css') { if(!defined($cssc = $colors{$lastcolor})) { $cssc = sprintf("c%x", $cc); $cc ++; $colors{$lastcolor} = $cssc; $css .= ".$cssc {color:#$lastcolor}\n"; } $body .= "<span class='$cssc'>"; } else { $body .= "<font color='#$lastcolor'>"; } } # end &startcolor sub endcolor() { if($mode eq 'css') { $body .= "</span>"; } else { $body .= "</font>"; } } # end &endcolor sub usage($) { my $exit = shift; print "$id: usage\n", <<USAGEnotes; colorizeascii [options] textfile ppmfile Options: -h --help print this message -t --title TITLE use TITLE as html title -c --css use CSS for colors -h --html use HTML 3.2 for colors -b --bgcolor COLOR use COLOR as background color -f --fontsize SIZE use SIZE as font size (CSS only) USAGEnotes exit($exit); } # end &usage
* Eli the Bearded wrote: > In alt.ascii-art, Troy Piggins <_usenet-0610@piggo.com_> wrote: >> * 3Dimka wrote: >> > Has anyone tried Characterizer? >> > it automatically converts images to text: >> > http://aolej.com/free.html#Chara >> Do you know of an equivalent for linux? > > Get the PBM Tools (or Netpbm) package and use pbmtoascii (comes > with the package) or hunt the Google archives for my pgmtoascii > script. Got it. > Actually, now I have a colorizer that I use with it, too. Example > usage: > > djpeg IMAGE.jpg > IMAGE.ppm > pnmscale -yscale 0.25 -xscale 0.5 IMAGE.ppm > IMAGE-scaled.ppm > ppmtopgm IMAGE-scaled.ppm > IMAGE-scaled.pgm Got this far... > # sometimes a pnminvert of the pgm file will help a lot > pgmtoascii IMAGE-scaled.pgm > IMAGE-scaled.txt Found it. > colorizeascii IMAGE-scaled.txt IMAGE-scaled.ppm > IMAGE-scaled.html This line I got an error: $ colorizeascii image.txt image-scaled.ppm > image.html colorizeascii: text error image.txt: not enough characters So close yet so far... > Look for the colorizer at the end of this post. <snip> -- Troy Piggins ,-o o ) Ubuntu linux 6.06 http://ubuntu.com RLU#415538 http://counter.li.org `-o uptime: 16:27:50 up 14 days,9:22,2 users,load average:0.19,0.06,0.01
In alt.ascii-art, Troy Piggins <use...@piggo.com> wrote: > * Eli the Bearded wrote: > > Actually, now I have a colorizer that I use with it, too. Example > > usage: > > > > djpeg IMAGE.jpg > IMAGE.ppm > > pnmscale -yscale 0.25 -xscale 0.5 IMAGE.ppm > IMAGE-scaled.ppm > > ppmtopgm IMAGE-scaled.ppm > IMAGE-scaled.pgm > > # sometimes a pnminvert of the pgm file will help a lot > > pgmtoascii IMAGE-scaled.pgm > IMAGE-scaled.txt > > colorizeascii IMAGE-scaled.txt IMAGE-scaled.ppm > IMAGE-scaled.html > > This line I got an error: > > $ colorizeascii image.txt image-scaled.ppm > image.html > colorizeascii: text error image.txt: not enough characters Ah. That's right. The pgmtoascii previously posted has a bug that drops the last few letters of the last line, most of the time. Updated version at the end of this post. > So close yet so far... The colorizer doesn't need ASCII art for the text input. So if you want to create stuff like the linux kernel colorized to show Tux, you can do that. This stuff makes mod_gzip (or the like) a good idea. Elijah ------ #!/usr/bin/perl -w # Convert PGM to ASCII art. # B. Elijah Griffin / Eli the Bearded 27 Dec 1999 use strict; use integer; use vars qw( $in $type $x $y $max $id %map $custommap $i $last ); $id = $0; $id =~ s:.*/::; $custommap = 0; %map = ( # The keys are the letter 'd' followed by a decimal number of a character. # Alternatively the raw character can be used, but the 'd' form will # override if both are defined. # d000 => ' ', # 00 # d051 => '.', # 33 # d102 => ':', # 66 # d153 => 'I', # 99 # d204 => 'V', # cc # d255 => 'M', # ff d000 => ' ', d016 => '.', d032 => ',', d048 => ';', d064 => '+', d080 => 'x', d096 => 'z', d112 => 'm', d128 => 'X', d144 => 'Y', d160 => 'U', d186 => 'C', d202 => 'O', d218 => 'M', d234 => 'W', d256 => '%', ); # Fill in holes. $last = ' '; for ($i = 0; $i < 256; $i++) { $i = sprintf("%03d", $i); if (defined($map{"d$i"})) { $last = $map{"d$i"}; } else { $map{"d$i"} = $last; } } while (defined($ARGV[0]) and $ARGV[0] =~ /^-(.*)/) { my $arg = $1; shift; if ($arg eq '-help' or $arg eq '-version' or $arg eq 'v') { &usage(0); } elsif ($arg eq 'm' or $arg eq '-map') { &readmap($ARGV[1]); } } # Add to map the character versions of the numerical mappings. my @map = keys %map; foreach (@map) { s/^d//; $map{chr($_)} = $map{"d$_"}; } if ($ARGV[0]) { open(STDIN,"< $ARGV[0]") or die "$id: Can't open '$ARGV[0]': $!\n"; } $in = '#'; while($in =~ /^#/) { $in = <STDIN> } if ($in =~ s/^P([25])\s*//) { $type = $1; } else { warn "$id: no portable graymap image file found\n"; exit(1); } read(STDIN,$in,1024,length($in)); # Eat comments, if the version allows comments if ($type < 4 and $in =~ tr:#:#:) { while ($in =~ s/(^|\cm|\cj)#[^\cj\cm]*([\cm\cj])/$1$2/g) { read(STDIN,$in,256,length($in)); } } if ($in =~ s/^\s*(\d+)\s+(\d+)\s+//) { $x = $1; $y = $2; } else { warn "$id: no dimensions found in image\n"; exit(1); } if ($in =~ s/^\s*(\d+)\s+//) { $max = $1; } else { warn "$id: no max value found in image\n"; exit(1); } if ($max != 255 and !$custommap) { warn "$id: Internal map is for 255 grays, this has $max grays\n"; } my $done = 0; my $col = 0; my $pixel = 0; my $chr; while($done < 2) { if (length($in) < 4) { if (!read(STDIN,$in,1024,length($in))) { $done = 1; } elsif ($type == 2) { # Nuke any leading whitespace if this is a text based PGM file. $in =~ s/^\s+//; } } if ($type == 5) { $in =~ s/^(.)//s; $chr = $1; } else { if ($done) { ($chr) = $in =~ s/^(\d+)\s*//s; } else { ($chr) = $in =~ s/^(\d+)\s+//s; } if (!defined($chr)) { warn "$id: Missing gray value!\n"; next; } $chr = sprintf("d%03d", $chr); } if (!defined($map{$chr})) { my $pchar = $chr; my $new = ' '; if (!($pchar =~ /^d(\d+)/)) { $pchar = sprintf("%03d",$1); } if ($pchar > ($max /2)) { $new = 'M'; } warn "$id: Gray $pchar missing from map using <$new>\n"; $map{$chr} = $new; } print $map{$chr}; $pixel ++; $col++; if ($col == $x) { print "\n"; $col = 0; } if($done and $in eq '') { $done = 2; } if ($pixel > ($x * $y)) { die "Too many pixels\nin=$in\n" unless $done == 2; } } print "\n"; exit(0); sub usage ($) { my $exit = shift; print "$id: usage\n", <<USAGEnotes; pgmtoascii [option] [file] Options: -h --help print this message -m --map MAPFILE use MAPFILE for gray to ascii map USAGEnotes exit($exit); } # end &usage # A really crude way to read in the graymapping file. sub readmap ($) { my $file = shift; do $file or die "$id: Can't read map: $!\n" } # end &readmap
* Eli the Bearded wrote: > In alt.ascii-art, Troy Piggins <use...@piggo.com> wrote: >> * Eli the Bearded wrote: >> > Actually, now I have a colorizer that I use with it, too. Example >> > usage: >> > >> > djpeg IMAGE.jpg > IMAGE.ppm >> > pnmscale -yscale 0.25 -xscale 0.5 IMAGE.ppm > IMAGE-scaled.ppm >> > ppmtopgm IMAGE-scaled.ppm > IMAGE-scaled.pgm >> > # sometimes a pnminvert of the pgm file will help a lot >> > pgmtoascii IMAGE-scaled.pgm > IMAGE-scaled.txt >> > colorizeascii IMAGE-scaled.txt IMAGE-scaled.ppm > IMAGE-scaled.html >> >> This line I got an error: >> >> $ colorizeascii image.txt image-scaled.ppm > image.html >> colorizeascii: text error image.txt: not enough characters > > Ah. That's right. The pgmtoascii previously posted has a bug that > drops the last few letters of the last line, most of the time. > Updated version at the end of this post. Got it. >> So close yet so far... > > The colorizer doesn't need ASCII art for the text input. So if > you want to create stuff like the linux kernel colorized to show > Tux, you can do that. > > This stuff makes mod_gzip (or the like) a good idea. $ colorizeascii image-scaled.txt image-scaled.ppm > image-scaled.html colorizeascii: no portable graymap image file found :( Does $TERM etc affect it? -- Troy Piggins ,-o o ) Ubuntu linux 6.06 http://ubuntu.com RLU#415538 http://counter.li.org `-o uptime: 10:19:50 up 15 days,3:14,2 users,load average:0.00,0.01,0.00
In alt.ascii-art, Troy Piggins <use...@piggo.com> wrote: > $ colorizeascii image-scaled.txt image-scaled.ppm > > image-scaled.html > colorizeascii: no portable graymap image file found I don't see how my code could generate that error. $ grep die ~/bin/colorizeascii die "$id: unrecognized option: -$arg\n"; die "$id: need two input files: textin ppmin\n"; die "$id: one or more input file does not exist\n"; die "$id: can't open ppm file $ppmin: $!\n"; die "$id: can't open text file $textin: $!\n"; die "$id: ppm error $ppmin: $$ppm_r{error}\n"; die "$id: ppm error $ppmin: not a pixmap\n"; die "$id: text error $textin: not enough characters\n"; $ Image::PBMlib might[*] have problems with PPM files that have comments (eg, stuff Gimp produces) but even still grepping for 'portable' in the PBMlib.pm file only gives results from the POD documentation: $ grep portable /usr/lib/perl5/site_perl/5.6.1/Image/PBMlib.pm This is primarily a library for reading portable bitmap (PBM), portable graymap (PGM), and portable pixmap (PPM) files. These have a very simple format which is the key to be "portable". $ > Does $TERM etc affect it? Nope. No environment variables harmed^Wused in either colorizeascii or Image::PBMlib. Elijah ------ [*] I need to release an update to that module.
* Eli the Bearded wrote: > In alt.ascii-art, Troy Piggins <use...@piggo.com> wrote: >> $ colorizeascii image-scaled.txt image-scaled.ppm > >> image-scaled.html >> colorizeascii: no portable graymap image file found > > I don't see how my code could generate that error. > > $ grep die ~/bin/colorizeascii > die "$id: unrecognized option: -$arg\n"; > die "$id: need two input files: textin ppmin\n"; > die "$id: one or more input file does not exist\n"; > die "$id: can't open ppm file $ppmin: $!\n"; > die "$id: can't open text file $textin: $!\n"; > die "$id: ppm error $ppmin: $$ppm_r{error}\n"; > die "$id: ppm error $ppmin: not a pixmap\n"; > die "$id: text error $textin: not enough characters\n"; > $ Not 'die', 'warn' : $ grep -n graymap ~/bin/colorizeascii 77: warn "$id: no portable graymap image file found\n"; 188:# A really crude way to read in the graymapping file. > Image::PBMlib might[*] have problems with PPM files that have > comments (eg, stuff Gimp produces) but even still grepping > for 'portable' in the PBMlib.pm file only gives results from > the POD documentation: > > $ grep portable /usr/lib/perl5/site_perl/5.6.1/Image/PBMlib.pm > This is primarily a library for reading portable bitmap (PBM), > portable graymap (PGM), and portable pixmap (PPM) files. These > have a very simple format which is the key to be "portable". > $ > >> Does $TERM etc affect it? > > Nope. No environment variables harmed^Wused in either colorizeascii > or Image::PBMlib. -- Troy Piggins ,-o o ) Ubuntu linux 6.06 http://ubuntu.com RLU#415538 http://counter.li.org `-o uptime: 13:35:22 up 17 days,6:30,2 users,load average:0.01,0.04,0.01
Related ASCII art in the Gallery
Explore these categories from our collection of 11,000+ artworks:
Make your own ASCII art
Turn images, text or 3D into ASCII, or draw your own – right in your browser.
About this thread.
These messages were posted publicly to the newsgroup
alt.ascii-art
in 2006 and are mirrored here unchanged as part of the Historic Archives – only email addresses are masked.
The artwork and text belong to their original authors: if you copy a piece, keep the artist's initials or signature intact and credit them where you can.
Are you one of the authors? Contact us to get your posts attributed, connected to your artist profile, or removed.
Report this message
Help us keep the archive clean and accurate. Reports are reviewed by a person – nothing is changed automatically.