PHP Developers Network

imagecreatefromjpeg: additions not dipsplaying proper color
Page 1 of 1

Author:  WoodyNaDobhar [ Mon Dec 27, 2004 10:01 pm ]
Post subject:  imagecreatefromjpeg: additions not dipsplaying proper color

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:

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 ]

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/';

// 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.long, FROM CENSORED as t1, CENSORED as t2 WHERE", $db) or

        die (mysql_error());






        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


        // 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.




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 ]
Syntax: [ Download ] [ Hide ]
tags where approriate when posting code. Read:  </span>

Author:  feyd [ Mon Dec 27, 2004 10:11 pm ]
Post subject: 

Moved to Graphics.

Author:  WoodyNaDobhar [ Mon Dec 27, 2004 10:21 pm ]
Post subject: 

Sorry 'bout that 8) duly noted...

Author:  onion2k [ Tue Dec 28, 2004 6:05 am ]
Post subject: 

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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group