Friday, 31 August 2007

Photoshop Scripts for ImagePyramid Tiles

The KML2.2 PhotoOverlay supports ImagePyramid tiling, where large images are split into sets of 256x256 pixel tiles. Each set is at a different zoom level, with zoom level 0 containing a single tile with a small version of the whole image. Each increment of zoom level quadruples the number of tiles, until the highest level covers the entire image at full resolution. A better explanation is given in the Google Earth KML documentation.

As you can imagine, creating all those tiles can be something of a chore. For this reason I've tried my hand at writing Photoshop CS2 scripts to automate the task. Download MakeJPGImagePyramid.jsx and MakePNGImagePyramid.jsx and store them in your C:\Program Files\Adobe\Adobe Photoshop CS2\Presets\Scripts folder (or the equivalent Mac folder of course). Load your image, then run the png or jpg version of the script. Tiles will be placed in the same folder as the source image, with the source image file name postfixed with "_[level]_[row]_[col]".

The .png version will preserve any transparent areas of the image as transparent areas of the tiles.

These are the first Photoshop scripts I've attempted, so please forgive any silliness in their construction - I welcome any suggestions for their improvement!

The next stage is to do a script that saves in png when the tile has any non-opaque pixels and jpg otherwise. I'm not sure how to do this yet (check a histogram of the tile alpha channel perhaps, or select opaque pixels and check selection dimensions?), but I'll post it up when it's done.

No comments: