Files
pmgr/views/maps/image.ctp
abijah 23ec1b6b20 Adding mapping ability. Incomplete as of yet, but coming along nicely.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@32 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 01:47:12 +00:00

96 lines
2.8 KiB
PHP

<?php /* -*- mode:PHP -*- */
// Create the image
$image=imagecreate($info['width'], $info['depth']);
// Allocate our color palate
foreach ($info['palate'] AS &$area) {
foreach ($area AS &$type) {
foreach ($type AS &$rgb) {
if (is_array($rgb)
&& isset($rgb['red'])
&& isset($rgb['green'])
&& isset($rgb['blue'])) {
$rgb['color'] = imagecolorallocatealpha($image,
$rgb['red'],
$rgb['green'],
$rgb['blue'],
isset($rgb['alpha']) ? $rgb['alpha'] : 0);
}
}
}
}
if ($info['border']) {
// Create border around image
imageline($image,
0, 0,
0, $info['depth'],
$info['palate']['main']['layout']['border']['color']);
imageline($image,
0, 0,
$info['width'], 0,
$info['palate']['main']['layout']['border']['color']);
imageline($image,
$info['width']-1, 0,
$info['width']-1, $info['depth']-1,
$info['palate']['main']['layout']['border']['color']);
imageline($image,
0, $info['depth']-1,
$info['width']-1, $info['depth']-1,
$info['palate']['main']['layout']['border']['color']);
}
// Go through each unit, placing it on the map
foreach ($info['units'] AS $unit) {
// Draw the unit borders
imageline($image,
$unit['left'], $unit['top'],
$unit['right'], $unit['top'],
$info['palate']['main']['layout']['wall']['color']);
imageline($image,
$unit['right'], $unit['top'],
$unit['right'], $unit['bottom'],
$info['palate']['main']['layout']['wall']['color']);
imageline($image,
$unit['right'], $unit['bottom'],
$unit['left'], $unit['bottom'],
$info['palate']['main']['layout']['wall']['color']);
imageline($image,
$unit['left'], $unit['bottom'],
$unit['left'], $unit['top'],
$info['palate']['main']['layout']['wall']['color']);
// Fill the unit according to its status
imagefilledrectangle($image,
$unit['left']+1, $unit['top']+1, $unit['right']-1, $unit['bottom']-1,
$info['palate']['unit'][$unit['status']]['bg']['color']);
// If the unit is wide enough, run the text horizontal,
// otherwise, we'll have to run it vertical.
if ($unit['width'] > 100) {
imagestring($image, 1,
$unit['left']+3, $unit['top']+3,
$unit['name'],
$info['palate']['unit'][$unit['status']]['fg']['color']);
}
else {
imagestringup($image, 1,
$unit['left']+3, $unit['bottom']-3,
$unit['name'],
$info['palate']['unit'][$unit['status']]['fg']['color']);
}
}
header("Content-type: image/png");
if (! imagepng($image)) {
die("Couldn't output image!");
}
// Clear image from memory
imagedestroy($image);
// Closing PHP tag intentionally omitted