Skip to content

Instantly share code, notes, and snippets.

@tohka
Created January 30, 2019 13:40
Show Gist options
  • Save tohka/04245e0dab7aad24f3908d7b744f8a6c to your computer and use it in GitHub Desktop.
Save tohka/04245e0dab7aad24f3908d7b744f8a6c to your computer and use it in GitHub Desktop.
<?php
$x = (string)filter_input(INPUT_GET, 'x');
$y = (string)filter_input(INPUT_GET, 'y');
$z = (string)filter_input(INPUT_GET, 'z');
$text = '';
$pattern = '/^\d+$/';
if(preg_match($pattern, $x) > 0 && preg_match($pattern, $y) > 0 &&
preg_match($pattern, $z) > 0){
$text = $z . '/' . $x . '/' . $y;
}
$img = imagecreatetruecolor(256, 256);
$fg = imagecolorallocatealpha($img, 255, 0, 0, 0);
$bg = imagecolorallocatealpha($img, 0, 0, 0, 127);
imagealphablending($img, true);
imagesavealpha($img, true);
imagefill($img, 0, 0, $bg);
imagerectangle($img, 0, 0, 255, 255, $fg);
if($text !== ''){
$font = '/usr/share/fonts/ipa-gothic/ipag.ttf';
$fontsize = 16;
$bbox = imagettfbbox($fontsize, 0, $font, $text);
imagettftext($img, $fontsize, 0,
128 - ($bbox[2]-$bbox[0])/2,
128 - ($bbox[7]-$bbox[1])/2,
$fg, $font, $text);
}
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>
@tohka
Copy link
Author

tohka commented Jan 30, 2019

It generates XYZ tile with 'z/x/y' index. (requirements: php-gd)

usage: http://hostname/tile.php?z={z}&x={x}&y={y}

tile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment