This is a screenshot of some text typed in a text editor:
This is the same text at a larger size.
Notice how visible the aliasing is on letters with prominent diagonal strokes like
z. This issue is a major reason why raster fonts have lost popularity to “scalable” formats like TrueType.
But maybe this isn't an inherent problem with raster fonts, just with the way scaling of them is typically implemented. Here's an alternative rendering using simple bilinear interpolation combined with thresholding.
This is smoother, but not ideal. Diagonal strokes are still bumpy, and curved letters like
o are still polygons. This is especially noticeable at large sizes.
So is there a better way?
Write a program that takes three command-line arguments.
resize INPUT_FILE OUTPUT_FILE SCALE_FACTOR
- INPUT_FILE is the name of the input file, which is assumed to be an image file containing black text on a white background. You may use any mainstream raster image format (PNG, BMP, etc.) that's convenient.
- OUTPUT_FILE is the name of the output file. It can be either a raster or vector image format. You may introduce color if you're doing some ClearType-like subpixel rendering.
- SCALE_FACTOR is a positive floating-point value that indicates how much the image may be resized. Given an x × y px input file and scaling factor s, the output will have a size of sx × sy px (rounded to integers).
You may use a third-pary open-source image processing library.
In addition to your code, include sample outputs of your program at scale factors of 1.333, 1.5, 2, 3, and 4 using my first image as input. You may also try it with other fonts, including proportionally-spaced ones.
This is a popularity contest. The entry with the greatest number of upvotes minus downvotes wins. In case of an exact tie, the earlier entry wins.
Edit: Deadline extended due to lack of entries. TBA.
Voters are encouraged to judge based primarily on how good the output images look, and secondarily on the simplicity/elegance of the algorithm.