GD transparency problem

From: Date: Sun, 11 May 2003 20:05:38 +0000
Subject: GD transparency problem
Groups: php.general 
Request: Send a blank email to php-general+get-147226@lists.php.net to get a copy of this message
Just when I thought I was getting a grip on PHP I decide to take on the GD library. -sigh- I have two problems which I'll put in two postings, so here's the first and here's what I'm trying to do: I want to display a map and overlay it with highlight sections according to the results of a database search. I tried doing this with floating boxes and GIFs, but had some issues with positioning the whole shebang on the page, so I thought I'd try some GD routines. And it's working to a degree. Having converted the files to PNG format, I now use the following code: $backimg = imagecreatefrompng('deptmaps/bckgrnd.png'); for ($i = 1; $i <= $dbrows ; $i++) { $overlay[$i] = imageCreateFromPNG("deptmaps/".$deptcode[$i].".png"); imageCopyMerge($backimg,$overlay[$i],0,0,0,0,350,394,10); } imagepng($backimg,"deptmaps/result.png"); echo "<IMG SRC='deptmaps/result.png'>"; (the $deptcode array holds values from '01' to '95' and there are files in the deptmaps folder named 01.png etc...) The problem is that I don't get a clear image overlaid by other clear images. The whole thing is rather murky (you can see what I mean at http://www.webvivant.com/features/deptfndr.php . Type 'or' into the 'Search by name' box and hit 'Find'). I think the problem lies with the PNG files not retaining their transparency. They look fine when I view them in Photoshop, but if I use a 'pct' value of 100 I see the last overlay as the desired image on a grey, rather than transparent, background. (BTW, I don't really understand that 'pct' value - I just tried experimenting with different values). So here's where I need help from wiser heads. I need a pointer to help me investigate this further. Is this a problem with the PNG files? Do I need to edit the colour map, maybe choosing a different transparency value? Or do I need to play with imagecolortransparent to try to set a new transparency value for the image created with imagecreatefrompng? Any pointers would be appreciated.

« previous php.general (#147226) next »