There are a bunch of Image to Ascii functions floating around the web, and there's a number of excellent classes available if the function is required for anything other than the basic entertainment and educational value.
This is my version of the Image to Ascii art function. It'll convert any GD supported image into ASCII art.
Consider the following image:
Using the function of echo beliefmedia_asciiart($image = 'info.jpg');
we'll render the following as text (I've taken a screenshot of the result).
The PHP Code
If you wanted to produce a form or something similar where users could convert images, you might consider styling the body to minimise the size of the returned HTML. You could do so as follows:
Considerations
The function literally replaces image pixels with individual RGB(A) values, so each pound symbol (representing each pixel) is styled and colourised individually. The function generates an enormous amount of HTML, and consumes quite a large amount of processing power. The larger the image, the more code will be returned, and the more CPU usage will be consumed. Our small (300x300) sample image rendered a 6.7MB HTML page.
If you had any need to actually keep a version of the generated code locally, you should choose to have it cached.