From 2fb5da215a7b286b71f8c4d0126c72a06e41935e Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Wed, 30 Jan 2013 03:23:26 -0800 Subject: Dynamic resizing of mapThumbnail. --- includes/maps.php | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'includes') diff --git a/includes/maps.php b/includes/maps.php index e5b6fdc..9ee6984 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -290,17 +290,48 @@ function DisplayMap($mapMatrix, $idprefix = 1, $style = 'normal', $speed = NULL) function DisplayMapThumbnail($map, $link = false) { $r = ''; //Prepare our return value: - if ($link) - $r .= ""; - else - $r .= "
"; + + $tileWidth = 1 / $map->width; + $tileHeight = $goalSize / $map->height; + + $sourceWidth = $map->width; + $sourceHeight = $map->height; + + $targetWidth = 150; + + $sourceRatio = $sourceWidth / $sourceHeight; + + // if ( $sourceRatio < $targetRatio ) { + $scale = $sourceWidth / $targetWidth; + // } else { + // $scale = $sourceHeight / $targetHeight; + // } + + $resizeWidth = (int)($sourceWidth / $scale); + $resizeHeight = (int)($sourceHeight / $scale); + + //$height = $width / ($tileWidth / $tileHeight); + //$height = round($height); + + $width = $resizeWidth.'px'; + $height = $resizeHeight.'px'; + + //$height = '100px'; + //if ($map-height > $map->width;) + $size = $size.'%'; + //$size = '1.2px'; + if ($link) { + $r .= "
"; + } else { + $r .= "
"; + } for ($y = 0; $y < $map->height; $y++) { //Number of Rows $r .= ""; for ($x = 0; $x < $map->width; $x++) { //Number of Columns $value = $map->tiles[$y][$x][TileValue]; $type = $map->tiles[$y][$x][TileType]; - $r .= ""; + $r .= ""; } $r .= ""; } -- cgit v1.2.3