Page 1 of 1

imagecolorallocatealpha just creating white field

Posted: Wed Jan 12, 2005 5:59 pm
by WoodyNaDobhar
http://www.dozerdevelopment.com/map_pop ... group_id=6

Task: draw color-coded transluscent polygons over lots that are sold or under contract. The origional lot must be visible thru it.

Problem: I can make it draw the polygons fine using imagecolorallocate, but when I use imagecolorallocatealpha (to make it see-through) with an alpha value greater than 0, it just turns it white, and not see-through at all.

Code:

Code: Select all

<?PHP

$getsold=mysql_query("SELECT `points` FROM `lots` WHERE `listinggroup_id` = '".$listinggroup_id."' AND `price` = '<font color=red><b>***SOLD***</b></font>'", $db) or
		die (mysql_error());
	$getuc=mysql_query("SELECT `points` FROM `lots` WHERE `listinggroup_id` = '".$listinggroup_id."' AND `price` = '<font color=red><b>***UNDER CONTRACT***</b></font>'", $db) or
		die (mysql_error());
		
	$img = imagecreatefromgif($tempmap);
	$black = imagecolorallocate($img, 0, 0, 0);
	$red = imagecolorallocatealpha($img, 255, 0, 0, 95);
	$green = imagecolorallocatealpha($img, 0, 255, 0, 95);
	while($sold=mysql_fetch_array($getsold)){
		
		$coords = explode("||", $sold['points']);
		$nopoints=0;
		$xy = "";
		foreach($coords as $c){
			
			$presplit = explode(",", $c);
			$xy[] = $presplit[0];
			$xy[] = $presplit[1];
			$nopoints++;
		
		};
		imagefilledpolygon($img, $xy, $nopoints, $red);
	
	};
	while($uc=mysql_fetch_array($getuc)){
	
		$coords = explode("||", $uc['points']);
		$nopoints=0;
		$xy = "";
		foreach($coords as $c){
			
			$presplit = explode(",", $c);
			$xy[] = $presplit[0];
			$xy[] = $presplit[1];
			$nopoints++;
		
		};
		
		imagefilledpolygon($img, $xy, $nopoints,$green);
	
	};
?>
PHP Version 4.3.4
GD Version bundled (2.0.15 compatible) (whatever that means *chuckle*)
GIF read support is enabled.
The origional image is a GIF, and it's being pumped out as a PNG.

Posted: Wed Jan 12, 2005 6:36 pm
by feyd
it may be a problem from the image being fiddled with isn't true color.

Posted: Thu Jan 13, 2005 12:25 pm
by WoodyNaDobhar
*nod* my thoughts exactly. I figured out how to use imagecopy(), and now life is good again *chuckle* Here's the revised, WORKING code 8)

Code: Select all

<?PHP

	$getsold=mysql_query("SELECT `points` FROM `lots` WHERE `listinggroup_id` = '".$listinggroup_id."' AND `price` = '<font color=red><b>***SOLD***</b></font>'", $db) or
		die (mysql_error());
	$getuc=mysql_query("SELECT `points` FROM `lots` WHERE `listinggroup_id` = '".$listinggroup_id."' AND `price` = '<font color=red><b>***UNDER CONTRACT***</b></font>'", $db) or
		die (mysql_error());
		
	$size = getimagesize($tempmap);
	$bgimg = imagecreatefromgif($tempmap);
	$img = imagecreatetruecolor($size[0], $size[1]);
	imagecopy($img, $bgimg, 0, 0, 0, 0, $size[0], $size[1]); 
	$black = imagecolorallocate($img, 0, 0, 0);
	$red = imagecolorallocatealpha($img, 255, 0, 0, 95);
	$green = imagecolorallocatealpha($img, 0, 255, 0, 95);
	while($sold=mysql_fetch_array($getsold)){
		
		$coords = explode("||", $sold['points']);
		$nopoints=0;
		$xy = "";
		foreach($coords as $c){
			
			$presplit = explode(",", $c);
			$xy[] = $presplit[0];
			$xy[] = $presplit[1];
			$nopoints++;
		
		};
		imagefilledpolygon($img, $xy, $nopoints, $red);
	
	};
	while($uc=mysql_fetch_array($getuc)){
	
		$coords = explode("||", $uc['points']);
		$nopoints=0;
		$xy = "";
		foreach($coords as $c){
			
			$presplit = explode(",", $c);
			$xy[] = $presplit[0];
			$xy[] = $presplit[1];
			$nopoints++;
		
		};
		
		imagefilledpolygon($img, $xy, $nopoints,$green);
	
	};

?>
Thanks for the input 8) There's nothing like a good night's sleep on it, tho 8)

Posted: Thu Jan 13, 2005 4:57 pm
by onion2k
Make absolutely sure you call imagedestroy() for each of the images you create or open if you're changing them. GD2 has a nasty habit of leaking memory if you don't..