git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@98 97e9348a-65ac-dc4b-aefc-98561f571b83
100 lines
2.9 KiB
PHP
100 lines
2.9 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 (isset($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'] > 20 || ($unit['width'] >= $unit['depth'])) {
|
|
imagestring($image, $unit['width']/25,
|
|
$unit['left']+3, $unit['top']+3,
|
|
$unit['name'],
|
|
$info['palate']['unit'][$unit['status']]['fg']['color']);
|
|
}
|
|
else {
|
|
imagestringup($image, $unit['depth']/25,
|
|
$unit['left']+3, $unit['bottom']-3,
|
|
$unit['name'],
|
|
$info['palate']['unit'][$unit['status']]['fg']['color']);
|
|
}
|
|
|
|
}
|
|
|
|
if ($debug) {
|
|
print("<H2>Would Now Render Image as image/png</H2>\n");
|
|
}
|
|
else {
|
|
header("Content-type: image/png");
|
|
if (! imagepng($image)) {
|
|
die("Couldn't output image!");
|
|
}
|
|
}
|
|
|
|
// Clear image from memory
|
|
imagedestroy($image);
|
|
|
|
// Closing PHP tag intentionally omitted
|