<?xml version="1.0" encoding="UTF-8"?>
<posts to="2009-01-07T17:34:45+00:00" from="2009-01-07T17:34:45+00:00"><post><id>8</id><rid>29</rid><title>Plotting on a World Map</title><section>Code Tutorial</section><author><username>thebluerhino.myopenid.com</username><name>Andrew Milsted</name></author><content><![CDATA[I needed to plot visitors to a web site onto a world map to demonstrate world wide coverage. I had an initial google around and couldn't really find anything. It didn't take too long to realise what i needed to make this work with my own script. I also chose to make it pretty so have gone for a lights at night look.
[data=size:700x350]2[/data]
[pb]
[b]Problem[/b]
* Put locations of visitors (for which i already had in a mysql database) on to a world map.

[b]Pre-Requisites[/b]
* The data (this example will assume from mysql)
* A World Map (I have gone for "AVHRR Pathfinder" shot from [url=http://www.evl.uic.edu/pape/data/Earth/]here[/url]) the bigger the better) 
* PHP with gd2 (I run this from the command line as it might take a while to render)

[b]Understanding the Maths[/b]
Firstly to make this work you need a linear [url=http://en.wikipedia.org/wiki/Map_projection#Cylindrical]cylindrical (latitude/longitude) projection[/url] world map, the ones from the source outlined above are. This means that the latitude/longitude are directly proportional to the x/y of the image. So if you have the dimensions the image as $img_x, $img_y you can then plot a long/lat with this:
[code=php]$pos_x = (int)(($img_x/2) + (($row['long']/180)*($img_x/2)));
$pos_y = (int)(($img_y/2) - (($row['lat']/90)*($img_y/2)));[/code]
For Longitude ($row['long']): the range is from -180°:180° so the above code work out the equivalent x position on the image. The same applies for Latitude($row['long']) with the range -90°:90°

With this sorted the rest of the code is simple.

[b]The Code[/b]
[code=php]//Setup Image
$imagein = "PathfinderMap.jpg";
$imageout = "output.jpg";

//Get Image Dimentions
list($img_x,$img_y) = getimagesize($imagein);

//Load in image
$im = imagecreatefromjpeg($imagein);

//Make Image "Night time"
$darkblue = imagecolorallocatealpha($im, 0x00, 0x00, 0x00, 25);
imagefilledrectangle($im, 0, 0, $img_x,$img_y, $darkblue);

//Mysql Bit
$mysqli = new mysqli("**","**","**","**");
if ($mysqli->connect_error) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

	$sql = "** Protected for Security **";

	
if ($result = $mysqli->query($sql)) {

    while ($row = $result->fetch_array(MYSQLI_ASSOC)) {	
    
	// work out long/lat on image
	$pos_x = (int)(($img_x/2) + (($row['long']/180)*($img_x/2)));
	$pos_y = (int)(($img_y/2) - (($row['lat']/90)*($img_y/2)));

	//if two positions share the same pixel then combine the result 
	if(!isset($data["{$pos_x}_{$pos_y}"])){
		$data["{$pos_x}_{$pos_y}"] = $row['Rows'];
	}else{
		$data["{$pos_x}_{$pos_y}"] += $row['Rows'];
	}

    }
    //free result set 
    $result->close();

}

// close connection 
$mysqli->close();

//Size of data array
$count = count($data);

echo "\\n"; //debug

foreach($data as $key=>$value){
	//Decides for each value
	//	$yellow is the light color
	//	$size is the diameter of the light
	if($value>10000){
		$yellow = imagecolorallocatealpha($im, 0xFF, 0xFF, 0x00,0);
		$size = 15;
	}elseif($value>1000){
		$yellow = imagecolorallocatealpha($im, 0xFF, 0xFF, 0x00,0);
		$size = 10;
	}elseif($value>100){
		$yellow = imagecolorallocatealpha($im, 0xFF, 0xFF, 0x00,0);
		$size = 7;
	}else{
		$yellow = imagecolorallocatealpha($im, 0xFF, 0xFF, 0x00,0);
		$size = 5;
	}
	
	// Draw light
	list($pos_x,$pos_y) = split("_",$key);
	imagefilledellipse($im, $pos_x, $pos_y, $size,$size, $yellow);

	$i++; //Debug
	echo "\\r$i/$count (".number_format(($i/$count)*100,1)."%)";
}

echo "\\rSaving Image this could take a bit\\n";
//save Image 
imagejpeg($im,$imageout);[/code]
So there we go, I welcome any comments.]]></content><html><![CDATA[<b>Code Tags:</b> PHP;Mysql<br />
I needed to plot visitors to a web site onto a world map to demonstrate world wide coverage. I had an initial google around and couldn't really find anything. It didn't take too long to realise what i needed to make this work with my own script. I also chose to make it pretty so have gone for a lights at night look.<br style="clear:left;"/><div class="dataPic datathumb"  onclick="javascript:var blob = window.open('/data/2.html','popup','scrollbars=1;menubar=no,height=750,width=680,resizable=yes,toolbar=no,location=no,status=no');" style="width:700px; height:auto;"><div style="background-repeat: no-repeat; background-position: center center; background-image: url(/getdata.php?bit=2&width=700&height=350&thumb=1); width:700px; height:350px; "></div>Plotting on a World Map (Website Visitors)</div><br style="clear:left;"/><!--page--><br style="clear:left;"/><b>Problem</b><br style="clear:left;"/>* Put locations of visitors (for which i already had in a mysql database) on to a world map.<br style="clear:left;"/><br style="clear:left;"/><b>Pre-Requisites</b><br style="clear:left;"/>* The data (this example will assume from mysql)<br style="clear:left;"/>* A World Map (I have gone for "AVHRR Pathfinder" shot from <a href="http://www.evl.uic.edu/pape/data/Earth/" class="ng_url">here</a>) the bigger the better) <br style="clear:left;"/>* PHP with gd2 (I run this from the command line as it might take a while to render)<br style="clear:left;"/><br style="clear:left;"/><b>Understanding the Maths</b><br style="clear:left;"/>Firstly to make this work you need a linear <a href="http://en.wikipedia.org/wiki/Map_projection#Cylindrical" class="ng_url">cylindrical (latitude/longitude) projection</a> world map, the ones from the source outlined above are. This means that the latitude/longitude are directly proportional to the x/y of the image. So if you have the dimensions the image as $img_x, $img_y you can then plot a long/lat with this:<br style="clear:left;"/><pre class="php" style="color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0; padding:5px;"><div style="font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; border-bottom: 1px solid #d0d0d0; padding: 0px;">php code:</div><span style="color: #000033;">$pos_x</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$img_x</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'long'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">180</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$img_x</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/><span style="color: #000033;">$pos_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$img_y</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lat'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$img_y</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><br style="clear:left;"/>For Longitude ($row['long']): the range is from -180°:180° so the above code work out the equivalent x position on the image. The same applies for Latitude($row['long']) with the range -90°:90°<br style="clear:left;"/><br style="clear:left;"/>With this sorted the rest of the code is simple.<br style="clear:left;"/><br style="clear:left;"/><b>The Code</b><br style="clear:left;"/><pre class="php" style="color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0; padding:5px;"><div style="font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; border-bottom: 1px solid #d0d0d0; padding: 0px;">php code:</div><span style="color: #666666; font-style: italic;">//Setup Image</span><br style="clear:left;"/><span style="color: #000033;">$imagein</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PathfinderMap.jpg&quot;</span><span style="color: #339933;">;</span><br style="clear:left;"/><span style="color: #000033;">$imageout</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;output.jpg&quot;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #666666; font-style: italic;">//Get Image Dimentions</span><br style="clear:left;"/><a href="http://www.php.net/list"><span style="color: #990000;">list</span></a><span style="color: #009900;">&#40;</span><span style="color: #000033;">$img_x</span><span style="color: #339933;">,</span><span style="color: #000033;">$img_y</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/getimagesize"><span style="color: #990000;">getimagesize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000033;">$imagein</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #666666; font-style: italic;">//Load in image</span><br style="clear:left;"/><span style="color: #000033;">$im</span> <span style="color: #339933;">=</span> imagecreatefromjpeg<span style="color: #009900;">&#40;</span><span style="color: #000033;">$imagein</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #666666; font-style: italic;">//Make Image &quot;Night time&quot;</span><br style="clear:left;"/><span style="color: #000033;">$darkblue</span> <span style="color: #339933;">=</span> imagecolorallocatealpha<span style="color: #009900;">&#40;</span><span style="color: #000033;">$im</span><span style="color: #339933;">,</span> 0x00<span style="color: #339933;">,</span> 0x00<span style="color: #339933;">,</span> 0x00<span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>imagefilledrectangle<span style="color: #009900;">&#40;</span><span style="color: #000033;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000033;">$img_x</span><span style="color: #339933;">,</span><span style="color: #000033;">$img_y</span><span style="color: #339933;">,</span> <span style="color: #000033;">$darkblue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #666666; font-style: italic;">//Mysql Bit</span><br style="clear:left;"/><span style="color: #000033;">$mysqli</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;**&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;**&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;**&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;**&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$mysqli</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect_error</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br style="clear:left;"/>    <a href="http://www.php.net/printf"><span style="color: #990000;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connect failed: %sn&quot;</span><span style="color: #339933;">,</span> mysqli_connect_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>    <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/><span style="color: #009900;">&#125;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/>	<span style="color: #000033;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;** Protected for Security **&quot;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$mysqli</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/>    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_array</span><span style="color: #009900;">&#40;</span>MYSQLI_ASSOC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<br style="clear:left;"/>&nbsp;<br style="clear:left;"/>	<span style="color: #666666; font-style: italic;">// work out long/lat on image</span><br style="clear:left;"/>	<span style="color: #000033;">$pos_x</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$img_x</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'long'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">180</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$img_x</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>	<span style="color: #000033;">$pos_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$img_y</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lat'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$img_y</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/>	<span style="color: #666666; font-style: italic;">//if two positions share the same pixel then combine the result </span><br style="clear:left;"/>	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000033;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;{$pos_x}_{$pos_y}&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br style="clear:left;"/>		<span style="color: #000033;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;{$pos_x}_{$pos_y}&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Rows'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br style="clear:left;"/>	<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br style="clear:left;"/>		<span style="color: #000033;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;{$pos_x}_{$pos_y}&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> <span style="color: #000033;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Rows'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br style="clear:left;"/>	<span style="color: #009900;">&#125;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/>    <span style="color: #009900;">&#125;</span><br style="clear:left;"/>    <span style="color: #666666; font-style: italic;">//free result set </span><br style="clear:left;"/>    <span style="color: #000033;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #009900;">&#125;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #666666; font-style: italic;">// close connection </span><br style="clear:left;"/><span style="color: #000033;">$mysqli</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #666666; font-style: italic;">//Size of data array</span><br style="clear:left;"/><span style="color: #000033;">$count</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000033;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//debug</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000033;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000033;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br style="clear:left;"/>	<span style="color: #666666; font-style: italic;">//Decides for each value</span><br style="clear:left;"/>	<span style="color: #666666; font-style: italic;">//	$yellow is the light color</span><br style="clear:left;"/>	<span style="color: #666666; font-style: italic;">//	$size is the diameter of the light</span><br style="clear:left;"/>	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$value</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">10000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br style="clear:left;"/>		<span style="color: #000033;">$yellow</span> <span style="color: #339933;">=</span> imagecolorallocatealpha<span style="color: #009900;">&#40;</span><span style="color: #000033;">$im</span><span style="color: #339933;">,</span> 0xFF<span style="color: #339933;">,</span> 0xFF<span style="color: #339933;">,</span> 0x00<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>		<span style="color: #000033;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span><br style="clear:left;"/>	<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$value</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br style="clear:left;"/>		<span style="color: #000033;">$yellow</span> <span style="color: #339933;">=</span> imagecolorallocatealpha<span style="color: #009900;">&#40;</span><span style="color: #000033;">$im</span><span style="color: #339933;">,</span> 0xFF<span style="color: #339933;">,</span> 0xFF<span style="color: #339933;">,</span> 0x00<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>		<span style="color: #000033;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><br style="clear:left;"/>	<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$value</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br style="clear:left;"/>		<span style="color: #000033;">$yellow</span> <span style="color: #339933;">=</span> imagecolorallocatealpha<span style="color: #009900;">&#40;</span><span style="color: #000033;">$im</span><span style="color: #339933;">,</span> 0xFF<span style="color: #339933;">,</span> 0xFF<span style="color: #339933;">,</span> 0x00<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>		<span style="color: #000033;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span><br style="clear:left;"/>	<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br style="clear:left;"/>		<span style="color: #000033;">$yellow</span> <span style="color: #339933;">=</span> imagecolorallocatealpha<span style="color: #009900;">&#40;</span><span style="color: #000033;">$im</span><span style="color: #339933;">,</span> 0xFF<span style="color: #339933;">,</span> 0xFF<span style="color: #339933;">,</span> 0x00<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>		<span style="color: #000033;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br style="clear:left;"/>	<span style="color: #009900;">&#125;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/>	<span style="color: #666666; font-style: italic;">// Draw light</span><br style="clear:left;"/>	<a href="http://www.php.net/list"><span style="color: #990000;">list</span></a><span style="color: #009900;">&#40;</span><span style="color: #000033;">$pos_x</span><span style="color: #339933;">,</span><span style="color: #000033;">$pos_y</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/split"><span style="color: #990000;">split</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">,</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>	imagefilledellipse<span style="color: #009900;">&#40;</span><span style="color: #000033;">$im</span><span style="color: #339933;">,</span> <span style="color: #000033;">$pos_x</span><span style="color: #339933;">,</span> <span style="color: #000033;">$pos_y</span><span style="color: #339933;">,</span> <span style="color: #000033;">$size</span><span style="color: #339933;">,</span><span style="color: #000033;">$size</span><span style="color: #339933;">,</span> <span style="color: #000033;">$yellow</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/>	<span style="color: #000033;">$i</span><span style="color: #339933;">++;</span> <span style="color: #666666; font-style: italic;">//Debug</span><br style="clear:left;"/>	<a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>$i/$count (&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/number_format"><span style="color: #990000;">number_format</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$i</span><span style="color: #339933;">/</span><span style="color: #000033;">$count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;%)&quot;</span><span style="color: #339933;">;</span><br style="clear:left;"/><span style="color: #009900;">&#125;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>Saving Image this could take a bit<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br style="clear:left;"/><span style="color: #666666; font-style: italic;">//save Image </span><br style="clear:left;"/>imagejpeg<span style="color: #009900;">&#40;</span><span style="color: #000033;">$im</span><span style="color: #339933;">,</span><span style="color: #000033;">$imageout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre><br style="clear:left;"/>So there we go, I welcome any comments.<br/>
]]></html><datestamp>2009-01-07T17:34:45+00:00</datestamp><timestamp>2009-05-05T12:42:41+01:00</timestamp><blog>8</blog><key>33f391c8f9899a304e170e98afd0a5d3</key><metadata><code_tags>PHP;Mysql</code_tags></metadata><attached_data><data>http://blogs.bluerhinos.co.uk/data/2.xml</data><data>http://blogs.bluerhinos.co.uk/data/4.xml</data></attached_data><links><uri>http://blogs.bluerhinos.co.uk/uri/5</uri><permalink>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.html</permalink></links><formats><format type="text/html">http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.html</format><format type="text/xml">http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml</format><format type="image/png">http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.png</format></formats><revisions><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=8</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=9</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=10</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=11</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=12</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=13</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=14</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=15</revision><revision current="true">http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=29</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=28</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=16</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/8/Plotting_on_a_World_Map.xml?revision=17</revision></revisions><comments/></post></posts>

