Moore Spatial

GIS and Related Pursuits


SSTiles — Stupid Simple Tile Maker

SSTiles is a small project I’ve been working on. It’s a simple PHP script that generates XYZ slippy map tiles on demand.

Ideally you’ll use a correctly projected base image (a square image, in Web Mercator projection). Since the image is square, SSTiles will just slice it up, no scaling is needed.


Usage is simple. Place the sstiles.php library and the tile.php or pad.php helper script in a directory with your base map, and add the layer to your map like so:$Z/$X/$Y.png

For Leaflet, you would do:


For OpenLayers you would do:
var basemap = new OpenLayers.Layer.XYZ("Basemap", "${z}/${x}/${y}.png");

Basemap types


A Nice Square Map

A Nice Square Map

Other times it might not matter if the map is correctly projected, in which case you can use a non-square image which will be sliced and scaled so that resulting tiles are square.


A Non-Square Map Is Stretched To Be Square


And finally, for the real use case that I wrote this script, if you want to abuse Leaflet (or OpenLayers, etc.) to make a tiled image viewer for high-resolution images you can ask SSTiles to pad the image so that resulting tiles won’t be distorted.




  • Lets you use any image as a slippy map!
  • Generates slippy-map tiles from a single top-level image!
  • Stretches the image if it’s not square!
    • OR Pads the image if it’s not square!
  • Caches generated tiles!
  • Auto-updates cache when source file is updated!
  • Sends HTTP caching headers!
  • Supports GD and ImageMagick!


What Slippy Map Zoom Level Is Ideal For My Source Map?

If you’re creating XYZ tiles for your slippy map (eg. Leaflet or OpenLayers), and your source is a raster image, you might wonder which zoom level will display the map with the least artifacts.

Or you might not. In any case, if you do want to know what zoom level is ideal, here’s how you find it. The code is in PHP, but should be easy to translate to other languages.

$min_dimension = min($image_width_in_pixels,$image_height_in_pixels);
$zoom_level = round(log($min_dimension/256,2)

Take the smaller of the height or width[1], divide it by 256 and find the base-2 logarithm of that. You will likely need to round that result to get an integer value. That integer will be the zoom level which has to resize your image the least to produce the appropriate tiles.

[1] Really, your source map should likely be square since you’re probably using Web Mercator