- Joined
- Dec 11, 2007
- Messages
- 3,666
- Solutions
- 1
- Reaction score
- 125
- Location
- Warsaw, Poland
- GitHub
- tayandenga
- Twitch
- tayandenga
Well, I don't have anything to say, as it's based on Lua script by Mock, so all (almost! eace credits go to him. I've personally added a simple caching, so the image won't need to be generated each time someone wants to see it.
Original topic: http://otland.net/f81/hunting-graphics-56772/
EDIT:
Oh, and here's how it looks: http://wypas.eu/map.phtml
EDIT #2:
Here's my version (storing positions at database table, per world data), still gathering information: http://wypas.eu/images/active.php
Original topic: http://otland.net/f81/hunting-graphics-56772/
Code:
<?php
$config = array(
'cache' => 3 * 60 * 60, # seconds
'multiplier' => 10, # keep it max 10 (for small servers), 5<->2 for huge ones
'x' => 1471,
'y' => 1141,
'file' => './map.png',
'store' => './pos.txt'
);
if(!file_exists($config['file']) || fileatime($config['file']) < time() - $config['cache'])
{
$img = imagecreatetruecolor($config['x'], $config['y']);
$n = floor(255 / $config['multiplier']);
$colors = array(
0 => imagecolorallocate($img, 0, $config['multiplier'], $config['multiplier'])
);
for($i = 1; $i <= $n; $i++)
{
if($i == $n)
{
$colors[imagecolorallocate($img, 0, $config['multiplier'] * $i, $config['multiplier'] * $i)] = imagecolorallocate($img, 255, 0, 0);
for($j = 0; $j <= $n; $j++)
{
if($j == $n)
{
$colors[imagecolorallocate($img, 255, $config['multiplier'] * $j, 0)] = imagecolorallocate($img, 255, 255, 0);
for($k = 0; $k <= $n; $k++)
$colors[imagecolorallocate($img, 255, 255, $config['multiplier'] * $k)] = imagecolorallocate($img, 255, 255, $config['multiplier'] * $k + $config['multiplier']);
}
else
$colors[imagecolorallocate($img, 255, $config['multiplier'] * $j, 0)] = imagecolorallocate($img, 255, $config['multiplier'] * $j + $config['multiplier'], 0);
}
}
else
$colors[imagecolorallocate($img, 0, $config['multiplier'] * $i, $config['multiplier'] * $i)] = imagecolorallocate($img, 0, $config['multiplier'] * $i + $config['multiplier'], $config['multiplier'] * $i + $config['multiplier']);
}
$positions = @file_get_contents($config['store']);
foreach(explode(';', $positions) as $position)
{
$pos = explode(',', $position);
$c = imagecolorat($img, $pos[0], $pos[1]);
if($colors[$c] != NULL)
imagesetpixel($img, $pos[0], $pos[1], $colors[$c]);
}
$size = count($colors) - 1;
for($i = 0; $i <= $size; $i++)
{
for($x = ($config['x'] - 5); $x <= $config['x']; $x++)
{
for($y = ($config['y'] - ($size - $i)); $y <= $config['y']; $y++)
{
$c = imagecolorat($img, $x, $y);
if($colors[$c] != NULL)
imagesetpixel($img, $x, $y, $colors[$c]);
}
}
}
imagepng($img, $config['file']);
}
else
$img = imagecreatefrompng($config['file']);
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>
EDIT:
Oh, and here's how it looks: http://wypas.eu/map.phtml
EDIT #2:
Here's my version (storing positions at database table, per world data), still gathering information: http://wypas.eu/images/active.php
Last edited: