Everything2
Near Matches
Ignore Exact
Full Text
Everything2

ASCII art conversion tool

created by yerricde

(thing) by yerricde (8.8 mon) (print)   ?   (I like it!) 2 C!s Sat Apr 07 2001 at 0:07:08

If you want to create ASCII art but don't have the time or skill to do it from scratch by hand, try this tool I whipped up in an hour. You'll need the Allegro library and a compatible compiler (preferably DJGPP or another GCC port) to build it; otherwise, grab a DOS binary at http://www.cs.rose-hulman.edu/~yerricde/ascii.zip .

<attachment name="ascii.c">

/*

ascii art conversion utility
Copyright 2001 Damian Yerrick

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including

without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

*/

/*

ascii.c converts a bitmap (in .bmp or .pcx format) to ASCII art.
It treats the least significant bitplane as a monochrome image,
making 0 dark and 1 light.  Each character sent to stdout represents
a 2x2 cell in the bitmap.

It uses the Allegro library to read the bitmap.  Allegro is a
multimedia library that has been ported to POSIX+X11, DOS, Windows,
BeOS, and Mac OS.  There are library extensions that allow Allegro
to handle other file formats such as PNG.
  http://alleg.sourceforge.net/allegro/

Because of the simple design of the program, it is also extremely
easy to port to other imaging APIs.

Compilation on DOS:
  gcc -Wall -O ascii.c -lalleg -o ascii.exe
Compilation on Linux:
  gcc -Wall -O ascii.c `allegro-config --libs` -o ascii

*/

#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>

/* the following line is not line noise but instead the
   characters that represent 2x2 pixel tiles */
char tiles[16] = "MPV\"b)\\'d/(`a., ";

int main(int argc, char **argv)
{
  BITMAP *bmp;
  int y;

  install_allegro(SYSTEM_NONE, &errno, atexit);

  if(argc != 2)
  {
    allegro_message("usage: ascii foo.bmp\n");
    return EXIT_FAILURE;
  }

  /* if you've installed Allegro library extensions for
     other bitmap formats, register their functions here */

  bmp = load_bitmap(argv[1], NULL);
  if(bmp == NULL)
  {
    allegro_exit();
    fprintf(stderr, "ascii Error: could not load bitmap `%s'\n", argv[1]);
    return EXIT_FAILURE;
  }

  for(y = 0; y < bmp->h; y += 2)
  {
    int x;
    for(x = 0; x < bmp->w; x += 2)
    {
      int c = 0;
      if(getpixel(bmp, x,   y  ) & 1)
        c |= 8;
      if(getpixel(bmp, x+1, y  ) & 1)
        c |= 4;
      if(getpixel(bmp, x,   y+1) & 1)
        c |= 2;
      if(getpixel(bmp, x+1, y+1) & 1)
        c |= 1;
      putchar(tiles[c]);
    }
    putchar('\n');
  }
  destroy_bitmap(bmp);

  return EXIT_SUCCESS;
}
/* Allegro uses this to translate main() into a WinMain() for some ports */
END_OF_MAIN();

</attachment>

To use it, make sure you have a monochrome .bmp or .pcx file and then:
ascii foo.bmp > foo.txt


printable version
chaos

E2 ASCII art Adding a DOS prompt entry to the Windows right click menu polyamory for monogamists Hammer and sickle
Other Names For Condoms Stuck behind an MS proxy server noddy Allegro
Bawls The Virgin Suicides XFree86 license dream generator
E2 HTML line noise The Simpsons ASCII Pic
My Imaginary Fish ASCII art WinMain Arm and Hammer
IA-64 Hyperbrowsing Passport Tonsilitis
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
The best nodes of all time:
High school can kill you
The Phantom of the Opera
Peano monster curve
The Pogues
Romantic Period Music
William Goldman
Gram-Schmidt Theorem
bed bug
How to carve a dodecahedron out of a cube
Innervisions
Fire Mountain
Ottoman Empire
Emmett Till
New Writeups
Tildeee
IANAL(idea)
antigravpussy
One fly amongst many(person)
sam512
Moon Base Shackleton, 1978(fiction)
Pavlovna
toy boy(person)
XWiz
tear jerker(review)
Heitah
Anarchy is Order(idea)
jessicaj
July 26, 2008(dream)
Berek
ABBA(person)
devolution
k-hole(place)
Nadine_2
The Sound Of Madness(review)
SwimmingMonkey
Conversations with Fo Fo, the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
This page courtesy of The Everything Development Company