imagecolorallocatealpha just creating white field

Need help with Photoshop, the GIMP, Illustrator, or others? Want to show off your work? Looking for advice on your newest Flash stuff?

Moderator: General Moderators

Post Reply
WoodyNaDobhar
Forum Newbie
Posts: 9
Joined: Mon Dec 27, 2004 8:43 pm

imagecolorallocatealpha just creating white field

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it may be a problem from the image being fiddled with isn't true color.
WoodyNaDobhar
Forum Newbie
Posts: 9
Joined: Mon Dec 27, 2004 8:43 pm

Post 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)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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..
Post Reply