<?php #-*-Mode: php; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/*
jjfMapper, a cartography program for PHP 4.
Copyright (C) 2004 John J Foerch
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//This file provides routines for accessing the icons
//that are built into JJFMapper. These icons are used
//to plot waypoints in formats like GPX and CoordinateList
//You can use the functions provided or you can pass an
//HTTP REQUEST like make=dot:f00 to get a png graphic
//directly.
if ($_SERVER['SCRIPT_FILENAME'] == __FILE__ &&
isset($_REQUEST['make']))
{
$m = $_REQUEST['make'];
//TODO: do I need to urldecode this data if magicquotesgpc is off?
list ($icon,$color) = explode (':',$m);
$x = imagecreatefromstring (GetBuiltInIcon($icon));
$color = strtoupper(ltrim($color,'#'));
if(strlen($color) == 3)
{
$color = $color[0] .$color[0] .$color[1] .
$color[1] .$color[2] .$color[2];
}
imagecolortransparent($x,imagecolorat($x,0,0));
ColorIcon ($x,$color);
header('Content-type: image/png');
imagepng ($x);
imagedestroy ($x);
}
function GetBuiltInIcon() {
$dot = '9805e474d0a0a1a0000000d09484442500000050000000508060000000d8f6625'.
'e0000006026b4744400ff00ff00ff0adb7a3900000090078495370000b0110000b01'.
'110f746f519000000704794d454704d401040c1f2248edf4e000000c49444144587c'.
'9531c14d0300201000b2bc073861411aa0920f32427e007048db6d62cb937288805b'.
'6596ec9fa492eedb6fed6da5e307fe57ec1f7fd880937607ec136c090fa7fe06c81a'.
'5b6e7b84272acc2d5217c000000009454e444ea240628';
$triangle = '9805e474d0a0a1a0000000d0948444250000007000000060802000000008'.
'c631120000006026b4744400ff00ff00ff0adb7a3900000090078495370000b00100'.
'00b00110da32db57000000704794d454704d4010405191c5093d4300000004944414'.
'4587c9d5c81bd00c03c03c48cd6a7e8739f28e72e1c72878e098b04ac9401829438d'.
'6df0023318ba5bdddd79e04f0b5f52922242555d79fc6f916ffcb0e25ed22117e3ef'.
'70000000009454e444ea240628';
if (func_num_args() == 0)
{
$d=$dot;
} else {
$m = strtoupper(func_get_arg(0));
if ($m == 'TRIANGLE') { $d = $triangle; }
else { $d = $dot; }
}
$r = pack ('h*',$d);
return $r;
}
function ColorIcon (&$dot,$color) {
if (is_int ($color)) $color = dechex ($color);
$color = ColorStringToResource ($color, $dot);
$c = imagecolorsforindex ($dot, $color);
$r = $c['red'];
$g = $c['green'];
$b = $c['blue'];
$w = imagesx($dot);
$h = imagesy($dot);
for ($j = 0; $j < $w; ++$j) {
for ($i = 0; $i < $h; ++$i) {
$c = imagecolorat($dot,$j,$i);
$rr = ($c >> 16) & 0xff;
$gg = ($c >> 8) & 0xff;
$bb = $c & 0xff;
if ($rr == 0 && $gg == 0 && $bb == 0) continue;
if ($rr == 255 && $gg == 255 && $bb == 255) continue;
$rr = floor(($rr / 255) * $r);
$gg = floor(($gg / 255) * $g);
$bb = floor(($bb / 255) * $b);
if ($rr == 0 && $gg == 0 && $bb == 0) { ++$rr; ++$gg; ++$bb; }
imagesetpixel ($dot,$j,$i,imagecolorallocate($dot,$rr,$gg,$bb));
}
}
}
?>