Re: GD transparency problem

From: Date: Mon, 12 May 2003 09:06:59 +0000
Subject: Re: GD transparency problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147275@lists.php.net to get a copy of this message
Steve M wrote:
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).
I believe the "pct" value is the "percentage" of the first/second image to use in the "merge" process. I think GD is "mixing" the two colors of the original pixels in each image together to achive the final color and "pct" tells GD how much to lean towards the first/second image. So that would cause your "ghost" effect. If you want a total blot-out overlay, try 100. Or maybe 0. Not sure which end of the scale you want. If that still doesn't work, are the "overlay" images just a bit of text? Forget doing a Merge and just draw the text with imagestring or other text-drawing functions in the GD API. (TrueText et al) http://php.net/imagestring Sample code: http://chatmusic.com/venueprogressmeter.phps http://chatmusic.com/venueprogressmeter.jpg

« previous php.general (#147275) next »