Tile Generation Part 2

By
Dave
Project
Published
12 May 2012 18:15
Last Modified
13 Jan 2013 17:22

I previously discussed a command-line tool for generating image tiles. I've updated the tool to include an additional parameter for image format. Usage is as follows, and the tool is available for download:

C:\tilegen /?
Generates a directory of tiles from a source image equirectangular projection

TILEGEN [drive:][path]filename level [/S=size] [/D=directory] [/F=filename] [/I=image]

   [drive:][path]filename   Soure image
   level                    Level of detail (0-based)
   /S=size                  Size of tile, default 256px
   /D=directory             Directory format, default level{0}
   /F=filename              Filename format, default {col}_{row}
   /I=image                 Image format (JPEG, PNG, TIFF), default JPEG (Compression=90)

Note that the source image is not scaled so must be correct level and size,
i.e. width (px) = 2 * 2^level * size, height (px) = 2^level * size

C:\>

Tile Generation

By
Dave
Project
Published
12 Nov 2011 18:30
Last Modified
13 Jan 2013 17:30

I needed to create image tiles to provide textures for level of detail rendering of planetary bodies. After looking around for a bit, I decided to write a simple tool for the job. For equirectangular1 projections, all I needed was to load big images and chop them up into a number of tiles according to a naming convention.

I decided not to support image resizing, as there are plenty of tools available which can do the job with an appropriate filter for the type of image.

The System.Drawing namespace can load big images using Bitmap.FromFile(), providing the image fits into memory, which in practical terms means Windows 64bit. The Graphics.DrawImageUnscaled() method can then be used to draw a tile, providing I maintain the dpi of the source image.

The command-line version is available for download. Usage is as follows:

C:\Tiles>tilegen /?
Generates a directory of tiles from a source image equirectangular projection

TILEGEN [drive:][path]filename level [/S=size] [/D=directory] [/F=filename]

   [drive:][path]filename   Soure image
   level                    Level of detail (0-based)
   /S=size                  Size of tile, default 256px
   /D=directory             Directory format, default level{0}
   /F=filename              Filename format, default {col}_{row}

Note that the source image is not scaled so must be correct level and size,
i.e. width (px) = 2 * 2^level * size, height (px) = 2^level * size

C:\Tiles>

To generate 8x256px tiles at level 1 from an appropriately-named 1024x512px image, I use:

C:\Tiles>tilegen 1024x512.jpg 1
Loading source image...done, 0.02s
Creating folder...done
Generating tile 8/8...done, 0.05s

C:\Tiles>

The optional parameters allow generation of different tile sizes, and output of custom directory and file path names.

1 Equirectangular is also known as Simple Cylindrical and Plate Carrée.

CAPTCHA Time

By
Dave
Project
Published
22 Jul 2010 23:10
Last Modified
13 Jan 2013 18:20

It's taken a few weeks for the spam-bots to notice my blog engine, but they're now starting to become more active. There are many options in the toolbox for dealing with spam comments, one of which is to add a CAPTCHA. This is a test in which a computer generates a challenge, and then attempts to verify that the response is generated by a human.

There are many CAPTCHA implementations available (reCAPTCHA is a good example), however I though it would be instructive to generate my own. The System.Drawing.Drawing2D namespace got me started, as shown below in Figure 1.

CAPTCHA image

Figure1. Initial CAPTCHA image (enlarged)

The image is generated by a controller action, returning a FileResult object with the appropriate content type. A new image is generated after a configurable interval. There are numerous ways to implement the CAPTCHA check when the comment form is submitted, the simplest of which is to have stored the CAPTCHA data in ASP.NET session state. Given this project is intended as a lightweight, personal blogging engine and that I wouldn't envisage scaling out across multiple servers, this doesn't seem a bad approach for the time-being.

Of course, it's rather sad that I have to use a CAPTCHA, and I apologise for inconveniencing anyone submitting a valid comment.