PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Sep 20, 2018 2:56 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Dec 27, 2004 10:01 pm 
Offline
Forum Newbie

Joined: Mon Dec 27, 2004 9:43 pm
Posts: 9
php version: 4.2.2

GD Version: 1.6.2 or higher //I dunno what it means by that, that's just what phpinfo() tells me.

image of which I speak: http://www.ohioamtgard.com/map_code.php

purpose: get a list of amtgard groups in Ohio and display a block over the location of each (the location being determined by zip/lat&long db comparing to the zip of the group) on the map.

Syntax: [ Download ] [ Hide ]
<?PHP



require ('CENSORED');



header ("Content-type: image/png");



function getlocationcoords($lat, $lon, $width, $height)

{  

    $x = (650-(($lon-80.53357) * ($width / 4.25216)));

    $y = (707-(($lat-38.465171) * ($height / 3.445505)));

    return array("x"=>round($x),"y"=>round($y));

}



// First we load the background/base map.

// We will also allocate the colors for the markers and the text, as well as the font



$im = imagecreatefromjpeg("images/ohio.jpg");

$black = imagecolorallocate($im, 0, 0, 0);

$red = imagecolorallocate ($im, 255,0,0);

$grey = imagecolorallocate ($im, 100,100,100);

$white = imagecolorallocate($im, 255, 255, 255);

$font = '/home/httpd/vhosts/ohioamtgard.com/httpdocs/Braveheart.ttf';



// Next need to find the base image size.

// We need these variables to be able scale the long/lat coordinates.



$scale_x = imagesx($im);

$scale_y = imagesy($im);



$getgroups=mysql_query("SELECT t1.lat, t1.long, t2.name FROM CENSORED as t1, CENSORED as t2 WHERE t1.zip=t2.location", $db) or

        die (mysql_error());

       

while($groups=mysql_fetch_array($getgroups)){

        $lat=$groups[0];

        $long=(0-$groups[1]);

        $text=$groups[2];

        settype($lat, "float");

        settype($long, "float");

// Now we convert the long/lat coordinates into screen coordinates

        $pt = getlocationcoords($lat, $long, $scale_x, $scale_y);

// Now mark the point on the map using a red 40 pixel rectangle

        imagefilledrectangle($im,$pt["x"]-20,$pt["y"]-20,$pt["x"]+20,$pt["y"]+20,$red);

        // Add some shadow for the text

        imagettftext($im, 18, 0, $pt["x"]+1, $pt["y"]+1, $grey, $font, $text);

        // Add the text

        imagettftext($im, 18, 0, $pt["x"], $pt["y"], $black, $font, $text);

};



// Return the map image.



imagepng($im);

imagedestroy($im);





?>


It looks like it's using the closest color already existing on the image, but when I added a red splotch to the image, it still displayed the incorrect color.

I get the impression it might have something to do with my GD version, but I've not seen a solution short of loading 2.0 | &gt;, something I don't have the authority to do.

Any help is welcomed 8)


feyd | Help us, help you. Please use
Syntax: [ Download ] [ Hide ]
and
Syntax: [ Download ] [ Hide ]
tags where approriate when posting code. Read:  <a href="http://forums.devnetwork.net/viewtopic.php?t=21171" class="postlink">Posting Code in the Forums</a></span>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 10:11 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
Moved to Graphics.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 10:21 pm 
Offline
Forum Newbie

Joined: Mon Dec 27, 2004 9:43 pm
Posts: 9
Sorry 'bout that 8) duly noted...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 6:05 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
Its the GD version alright. You can only create truecolour images with GD2. A way around it would be to reduce the number of colours in your map, convert it to a PNG, and load it using imagecreatefrompng().

Disclaimer: I think thats right.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group