<%@ page import="java.io.BufferedReader, java.io.InputStreamReader, java.io.IOException, java.io.UnsupportedEncodingException, java.net.URL, java.net.URLEncoder" %> <%! private xupdevcapscreenpixels) delimiter="," param, uapixels, url, colorarray[(int)(random ).append(resarray[0]); string[] } } private colorarray="value.split(" colorarray.length)]); } private encodedvalue="URLEncoder.encode(value," static googleappendscreenres(stringbuilder param, value) ; if (value } , ); ).append(resarray[1]); } } % random) & % googleappendurl(stringbuilder void ).append(param).append(=").append( " (uapixels="null)" !="null)" resarray="screenRes.split(delimiter); " screenres="xUpDevcapScreenpixels; " (resarray.length="2)" pagead=" " final http://pagead2.googlesyndication.com/pagead/ads? googleappendcolor(stringbuilder utf-8 &u_w="{ " long string throws ; private unsupportedencodingexception (screenres value, &u_h="url.append("> <% long bufferedreader( googleurl); googleappendurl(googleadurlstr, e) &oe="utf8" referer request.getremoteaddr()); googleadurlstr.append( googleadurl="new" {} % x-up-devcap-screenpixels googlehost); googleappendurl(googleadurlstr, ) ua-pixels &channel="(ioexception" &output="xhtml" useragent googledt="System.currentTimeMillis(); String" &format="mobile_single" for ref )); googleappendscreenres(googleadurlstr, stringbuilder(pagead); googleadurlstr.append( (request.getquerystring() ? } } ip googleurl : out.println(line); &markup="xhtml" host request.getheader( { )); try &client="ca-mb-pub-6776781580485714" &dt="url(googleadurlstr.tostring()); " new googlehost="(request.isSecure()" , + ).append(googledt); googleadurlstr.append( ad_type="text_image" url (line="reader.readLine())" !="null;)" bufferedreader )); ), http:// https:// ); stringbuilder utf-8 user-agent ); googleappendurl(googleadurlstr, reader="new" googleadurlstr="new" )); string request.getquerystring().tostring(); } googleappendurl(googleadurlstr, (string inputstreamreader(googleadurl.openstream(), ); googleadurlstr.append( line; catch>

Thursday, January 3, 2008

ASCII Generator



In the first in a series of tutorials on how to use the ASCGEN dotNET, I show you how to convert an image to a high quality fixed width text image with just a few simple steps and very little effort.

We will be going from this

Original Image to Output


First, a quick lesson about fonts or just skip ahead to the tutorial.

There are two main types of font: Fixed Width, which has one specific size for every character, and Variable Width, which has a fixed height but the width can vary between different characters.

Fixed width fonts such as Courier New, Lucida Console, Fixedsys are traditionally used for ASCII art, however most word processors use a variable width font like Times New Roman, or Arial.

When you have selected a fixed width font, at the top of the program you will see the “Ramp” toolbar used for setting the current ASCII ramp. When you use a variable width font, you will instead see the “Characters” toolbar, which is used for setting the conversion characters.

Fixed Width vs Variable Width Toolbar

The ASCGEN dotNET is the first and only program able to convert images into ASCII art made for variable width fonts. We will cover variable width font conversions in a future tutorial, but for now let’s start with the default fixed width font.

Tutorial One: Creating your first image

Get a suitable image into the program

For this tutorial I will be using the following image, which was taken from a royalty free stock photo archive.

Original Image

Go to “File/Load” or double-click the image area and select the image, or you can drag and drop the image onto the image tab or just copy it and paste it with “File/Import from Clipboard”.

Loaded Image

Select an area of the image
When we convert the image, its resolution is reduced to the output size in memory, which means that small details will be lost or difficult to see. To produce the best output, we need to zoom in and concentrate on the main subject of the image.

So, imagine a box around the person or thing you want to see, then click on a corner and drag to create the selection area.

Selected Image

Click and drag the box to move it around, and use the white boxes to adjust the size. Make the input image bigger by dragging the separator between the text and image if needed.

Select the output font
For this tutorial, we will leave it at the default font settings which are Lucida Console, 9pt. The “Auto” button on the toolbar should be pushed down by default, which has the program create an accurate ASCII ramp for the font, and the ramp box will be grayed out.

Switch to full screen mode
To get a better view of the output, switch to full screen by clicking the Full Screen Button button, or pressing F11. You could also hide the input image by clicking the Image Display Button or pressing F12.

Full Screen

Adjust the brightness/contrast and levels for the output
To get the best results, the ASCGEN dotNET allows you to adjust the output image in real time.

It does this in two ways. The first is a Brightness/Contrast control which does exactly what you expect. However, a much more recommended method is through the levels control.

Levels Control

This control shows you a histogram of the current image, and allows you to adjust the minimum, median and maximum values in exactly the same way as you would in photoshop and other photo applications. It will make the image use the whole range of the output ramp, and can drastically improve the results. Google photoshop levels for some proper explanations and tutorials.

First, click and drag the black slider to adjust the minimum level. Try and put it near the first peak. Then, click and drag the white slider to adjust the maximum level. Try and put it around the last peak. If necessary, adjust the grey slider a little to set the middle point of the range.

Because of the way these images work, there isn’t a smooth incremental range of characters for the output and it’s easier to work with the output then the graph. Just adjust the settings until you’re happy with the results.

The finished image

Save the text image
Now the image is finished, we just need to save it.

Go to “File/Save…” and the save dialog will appear. Set the “Save as type” drop down box for how you want to output the text image:

  • Plain Text - Save the text without any font information (remember to set the correct font when you display it)
  • Plain Text (Unicode) - Same as above, but will save as a unicode text file that can store ANSI and other non standard characters
  • Rich Text - Saves the text and font settings as a rtf file that can be opened by wordprocessors
  • XHTML 1.1 - Saves the image and font settings to a valid html file that can be opened by web browsers.

An alternative way to save the image is by clicking on “File/Save as an Image…”, which will output the text into an image format.

Save as an Image

This is useful if you want to make sure the image will be displayed looking exactly as it should look without having to worry about the font.

By default the image is resized to 75% of its original size, but you can adjust up to 100% (the actual text size) with the slider or down to 25%. Use the arrow keys to adjust the size in smaller increments to the exact dimensions you want. Click “Ok”, then set the output filename and type (.gif usually produces the smallest output sizes), and we’re done.

Output

Google
 
PalmProgramming