Jump to content

Recommended Posts

So I'm new to PHP GD, I cant understand why the PNG image will not go transparent, it's just showing a white background.

 

Could anyone help me out with this?

 

 

iSDMDci.jpg

 

<?php
$hour = date('H');
if ($hour  > 4 && $hour < 12) {
        $image = "day.png";
} elseif ($hour  > 11 && $hour < 19) {
         $image = "day.png";
} else {
         $image = "night.png";
}
$image = imagecreatefrompng( "$image" );
if (!$image) { /* See if it failed */
        header("(anti-spam-(anti-spam-content-type:)) $extList");
        $im = imagecreatetruecolor (150, 30); /* Create a blank image */
        $bgc = imagecolorallocate ($im, 255, 255, 200);
        $tc = imagecolorallocate ($im, 0, 0, 0);
        imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
        /* Output an errmsg */
        imagestring ($im, 1, 5, 5, "Error loading Image", $tc);
        imagepng($im);
        imagedestroy($im);
        die();
    }
header("(anti-spam-(anti-spam-content-type:)) image/png");
imagepng($image);
imagedestroy($image);
?>

Thanks, Sam

You need to call imagecolortransparent(). EG

imagecolortransparent ($im, imagecolorat($im,0,0));

which sets the transparent color to the color of the pixel at 0,0 (assuming that is a background colored pixel)

I have had luck using the imagealphablending($var, false) and imagesavealpha($var, true) in that order right after the imagecreatetruecolor().  The $var in those you would change to your appropriate var being used.

Edited by fastsol
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.