Jump to content

GDLIB Transparency


Staggan

Recommended Posts

Hello

 

I have looked at numerous posts on this but I seem unable to get it to work....

 

I trying to make the background to a generated PNG transparent... below is the code

 

 

 
 $dimensions = $this->getDimens($fh, $lw, $hpad, $vpad);
        $this->im   = imagecreate($dimensions['x'], $dimensions['y']);
        $bg         = iimagecolorallocate$this->im, 255, 255, 255); // Set background color.
  imagecolortransparent($this->im, $bg);
        $this->tc   = imagecolorallocate($this->im, 0, 0, 0); // Text color.
        $this->mkStr($dimensions['x'] - $hpad - imagefontwidth(LFONT)*strlen($tourName), $dimensions['y'] - $vpad/2, $tourName, LFONT); // Print tournament name.
 

 

 

Currently I just get a black image...

 

Any suggestions would be greatly appreciated

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/279972-gdlib-transparency/
Share on other sites

Mark the image to save the alpha channel details using imagesavealpha and set it to true. Then allocate your background color using imagecolorallocatealpha and set the alpha parameter to 127. Floodfill the image using imagefill with the background color, then you should get your transparent background.

Link to comment
https://forums.phpfreaks.com/topic/279972-gdlib-transparency/#findComment-1439948
Share on other sites

Hello

 

It still isn't working..

 

My code is now this:

 

 

 
   // Initial calls.
        $dimensions = $this->getDimens($fh, $lw, $hpad, $vpad);
        $this->im   = imagecreate($dimensions['x'], $dimensions['y']);
        $bg         = imagecolorallocate($this->im, 255, 255, 255); // Set background color.
  imagesavealpha($this->im, true);
  imagecolorallocatealpha($this->im, 255, 255, 255, 127);
  imagefill($this->im, 255, 255, 255);
  imagecolortransparent($this->im, $bg);
 

 

I get a white background now.....

 

This page is being shown via an iframe.. and I want the background on the calling page to show through....

 

Am I missing something?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/279972-gdlib-transparency/#findComment-1439963
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.