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

Edited by kicken
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.