Zoomify, TilePic and other mosaic

Several sites are using the TilePic image format to show sections of a larger image. The TilePic file format contains the image data for a limited number of resolutions (zoom levels) and all image parts (tiles) have the same dimensions. The first level contains the full image scaled to a single tile. The second level could contain 4 tiles of the same size, each containing a quarter of the image data at twice the resolution of the first level. The third level then contains 4 tiles for each tile of the second level, resulting in a total of 16 tiles for the full image. The advantage of the TilePic format is that the client only needs to download the specific tiles for the shown part of the image from the level with the correct resolution. The websites usually provide zoom and scroll functions to magnify a part of the image.

Downloading the high-resolution image from the TilePic file requires some knowledge on the location of the file on the server. This information can be found in the source code of the webpage and may for example be /photo/tilepic/image.tjp. For TilePic-clients implemented in Adobe Flash it may be required to capture network traffic with e.g. Wireshark to find the address of the server and the location of the file. The following script will download all tiles from all levels of the TilePic image defined by $file.

After downloading all tiles, the number of tiles ($cols and $rows) of the highest level can easily be determined. The $first parameter is the file number of the tile in the upper left corner in this level. The following script will stitch the tiles of the highest level to re-create the high-resolution image. The tiles in the last column and last row will not have the same dimensions as the other tiles, because the resolution of the original image is unlikely to be an exact multiple of a single tile. The programs montage and convert are part of the ImageMagick package.

#!/bin/bash

# Script to download tiles
# Radko Bankras
# Last update: 13 July 2013

url='http://www.tileserver.com/tiles/image_identifier/'
zoom=3
cols=8
rows=5

for ((i = 0; i < $rows; i++)) do
string=''
for ((j = 0; j < $cols; j++)) do
image=$zoom'-'$j'-'$i'.jpg'
file=$url$image
string=$string' '$image
wget -O $image $file -q
echo `expr $j + 1`' of '$cols' row '`expr $i + 1`', image '$image
done
montage $string -tile $cols''x1 -mode concatenate row$i.jpg
done

string=''
for ((i = 0; i < $rows; i++)) do
string=$string' 'row$i.jpg
done
convert $string -append final.jpg

string=$zoom'*.jpg'
rm $string
rm row*.jpg

The satellite photographs provided by Google Maps are also served in tiles and a similar script can be made to download the images of a particular area. However, the tiles have been named in a quadrant-like structure, which requires a more complicated script to stitch the tiles with rows and columns.

Zoomify is an alternative format to present zoomable images on websites. The tiles are stored as individual files on the server, with file names (e.g. 3-4-5.jpg) consisting of the zoom level (3), column position (4) and row position (5). A similar script can be written to download these files and stitch the tiles together for a high resolution image. Note that images consisting of a large number of tiles may be split (TileGroups) to limit the total number of files in each folder.