Jump to content

imagepng Not Transparent, Black Background


phprocker

Recommended Posts

Hey all.  I'm getting down the basics of the GD Library's image creation processes.  I'm trying to test out creating png images.  However, where there should be transparency there is a black background.  Here's my code mostly based on the image tutorial found here at phpfreaks.

 

<?php
// font
$font = 'c:\windows\fonts\arial.ttf';
$fontsize = 12;

// array of quotes
$quotes = array(
"I like pie.",
"Surf's Up.",
"Smoke em if you got em.",
"Game on.",
"I need TP for my bunghole.");

// select quote
$pos = rand(0,count($quotes)-1);
$quote = $quotes[$pos];

// image
$image = imagecreatefrompng('quote.png');

$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, 11, 0, 107, 32, $black, $font, $quote);
imagettftext($image, 11, 0, 105, 30, $white, $font, $quote);


// tell the browser that the content is an image
header('Content-type: image/png');
// output image to the browser
imagepng($image);

// delete the image resource 
imagedestroy($image);
?>

 

Cheers all, thanks!  8)

Thanks for the lightning fast reply and yes this does the trick for the background color.  However, it has also made transparent my text's shadow.

 

From the code above here's the text and shadow.

<?php $white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
//shadow
imagettftext($image, 11, 0, 107, 32, $black, $font, $quote);
//text
imagettftext($image, 11, 0, 105, 30, $white, $font, $quote);
?>

 

Any remedy?

 

Thanks again.

I thought you were on to something there and you might be.  However that did not work.  It seems that over at http://us.php.net/imagecolortransparent the first and latest comment is also exactly my problem.  The commenter has an uncanny approach.  Check it out, it may be interesting to yourself.

 

Does his route make sense?

 

Thanks much again.

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.