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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.