class weldMaps2PNG, transparency issues (multiple adding of PNG to PDF)

Marc Jansen jansen.marc at gmx.de
Mon Dec 4 14:34:57 EST 2006


Hi list,

today I encountered some problems with transparency in the class 
weldMaps2PNG.

My problem was that I was forced to run the image-creation-class within 
the printing module several times for one PDF. I added some welded maps 
to the PDF and afterwards I had to add some more welded maps. With the 
default settings in this class the module creates a white image of given 
size and  adds  the single images (some might be transparent) of the 
request URLs to this image.

Without changes, it was impossible to simply create the second bunch of 
maps and to just add them to the PDF, as the background of the images is 
white and not transparent.

I fixed this issue by replacing some of the lines in the class 
weldMaps2PNG (in the constructor-function):

old code:
------------------------------------------------------------
$image = imagecreatetruecolor($width, $height);
$white = ImageColorAllocate($image,255,255,255);
ImageFilledRectangle($image,0,0,$width,$height,$white);
------------------------------------------------------------

new code:
------------------------------------------------------------
// do not use imagecreatetruecolor,
// as the currently used PDF-creation-class
// has some problems with this 24-bit PNGs
$image = imagecreate($width, $height );
// allocate a color as usual
$white = imagecolorallocate($image,255,255,255);
// set this color to transparent
// no need to draw a rectangle in my case
$white = imagecolortransparent($image, $white);
------------------------------------------------------------

As for programming semantics and self-explaining code one might consider 
to rename the variable $white to $transparent... ;-)

Are there any opinions about this issue?

-- Marc





More information about the Mapbender_dev mailing list