Litetext for rendering text into a bitmap on Google App Engine Java

October 26, 2009
By

While developing Quick Bit Notes, I realized that the Google App Engine “sandbox” for Java doesn’t support AWT or other graphics Java classes, so I put together a simple “old-school” text rendering class that’s compatible with App Engine, called litetext.

This small package (less than 1000 lines of Java code) was developed to provide a small and simple package for rendering text into an image (bitmap). It was developed for Google App Engine use where AWT and BufferedImage et al do not exist. This small utility can be used to render text on App Engine within the constraints of the JRE Class White List. This is derived from the “pbmtext” utility from NETpbm Copyright (C) 1991 by Jef Poskanzer.

These are crude black-and-white bitmap fonts – no anti-aliasing. A small number of BDF fonts in fixed-sizes are bundled into the package: Courier, Lucida-Bold-Italic, Lucida-Medium, Lucida-Medium-Italic, LucidaBright-DemiBold, LucidaTypewriter, LucidaTypewriter-Bold, and a default serif font.

The following code snippet demonstrates use of litetext on App Engine:

byte[] bmp_data = fm.doRender(inputText, fontname);
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image bmpImage = ImagesServiceFactory.makeImage(bmp_data);
Transform flipit = ImagesServiceFactory.makeVerticalFlip();
Image newImage = imagesService.applyTransform(flipit, bmpImage, com.google.appengine.api.images.ImagesService.OutputEncoding.JPEG);

You can grab it via SVN at http://code.google.com/p/litetext/

There are docs on the project site for adding fonts and an example demo servlet is included. See the Live Demo.

Use this command to check out the latest project source code anonymously over HTTP:

svn checkout http://litetext.googlecode.com/svn/trunk/ litetext-read-only

One Response to Litetext for rendering text into a bitmap on Google App Engine Java

Buy Me A Beer

css.php