I have a map of mainland Britain that is split into 56 separate images, that joined together make a map of Great Britain. The tiles are split using the
British national grid reference system [en.wikipedia.org]
I also have a gazetteer of British towns and cities with co-ordinates, which is great as I can map the cities to their respective map locations, which I'm already doing.
To display the town dead-centre, sometimes more than 1 map image is needed, i.e. up to 4.
Each map image was supplied in tiff format, which I've converted to png, in png format they are averaging 1.5MB each.
I'm using GD to generate/centre/slice-dice the maps to display towns in a smaller resized image (i.e. zoom out a bit).
Is there an efficient method of grabbing slices of larger images? i.e. sometimes here I'm taking 4 1.5MB map squares and taking a section of each. I'm thinking it may be memory expensive and there's a better way of going about it.
This is the code I use where just one tile is concerned (i.e. the co-ordinates are not close to the edge of the map tile and other map tiles need to be loaded in)
<?php
// Gets just 1 map tile image and centre on co-ordinates given
$reference = 'NT4936'; // Usually grabbed from _GET
$d = 500; // final image size
$filename = substr($reference,0,2).'.png'; // map square NT (4000x4000 px)
$x = round(40 * substr($reference,2,2)) - ($d/2); // how far along X
$y = round(4000 - (40 * substr($reference,4,2)) - ($d/2); // how far down Y
header('Content-type: image/png');
list($width, $height) = getimagesize($filename);
// Resample
$image_p = imagecreatetruecolor($d,$d);
$image = imagecreatefrompng($filename);
imagecopyresampled($image_p,$image,0,0,$x,$y,$d,$d,$d,$d);
// Output
imagepng($image_p, null,75);
exit(0);
?>
So I guess I'm asking, is it unavoidably memory expensive using this script? Perhaps it is better just to save the image generated for each co-ordinates queried (more disk space required)