Page 1 of 1

problem with transparent Image

Posted: Mon Sep 29, 2008 2:40 am
by sneha1234
<?php

Header('Content-type: image/png');

$Img = imagecreate(100,100);

$Gray = imagecolorallocatealpha($Img, 0, 0, 255, 10);

$text = 'Testing...';

imageFilledRectangle($Img,0,0,100,100,$Gray);
imagecolortransparent($Img,$Gray);

$font = 'Shelley_AllegroScript.ttf';
imagettftext($Img, 20, 0, 10, 20, $Gray, $font, $text);
//imagestring($Img,4,0,0,$text,$Gold);
//imagecolortransparent($Img,$Gray);

imagepng($Img);

ImageDestroy($Img);
?>

i m not able see clear text image is transprent but text is not clear

Re: problem with transparent Image

Posted: Mon Sep 29, 2008 3:31 am
by onion2k
imagecreate() generates an 8 bit image. 8 bit PNG files only have a 1 bit alpha channel (sort of like a GIF). Use imagecreatetruecolor() instead so you're creating a 32 bit image (24 bit + an 8 bit alpha channel).

Re: problem with transparent Image

Posted: Mon Sep 29, 2008 5:37 am
by sneha1234
hi!
i m not getting Transparent image if i use "imagecreatetruecolor" actuall i want tranparent image on text on it..
thanks for reply..
<?php

Header('Content-type: image/png');


$Img=imagecreatetruecolor(100,30);

//$Img = imagecreate(110,30);

$Gray = imagecolorallocatealpha($Img, 0, 0, 255, 10);

$text = 'Testing..';

imageFilledRectangle($Img,0,0,100,100,$Gray);
imagecolortransparent($Img,$Gray);

$font = 'Shelley_AllegroScript.ttf';
imagettftext($Img, 20, 0, 10, 20, $Gray, $font, $text);
//imagestring($Img,4,0,0,$text,$Gold);
//imagecolortransparent($Img,$Gray);

imagepng($Img);

ImageDestroy($Img);
?>

Re: problem with transparent Image

Posted: Mon Sep 29, 2008 6:26 am
by onion2k
sneha1234 wrote:i m not getting Transparent image if i use "imagecreatetruecolor" actuall i want tranparent image on text on it..
That's right. You need to set the pixels of the image to transparent, or copy a transparent image over the whole area while imagesavealpha() is off.

I've actually got an example of how to create a transparent true color image on phpgd.com - http://www.phpgd.com/scripts.php?script=27

Re: problem with transparent Image

Posted: Mon Sep 29, 2008 6:46 am
by sneha1234
hi!
i have tried doing that here an ex:
imageSaveAlpha($image, true);
ImageAlphaBlending($image, false);

but this function r not working!
i hv also tried the link u provied but its not working..
if u can help futher...
thanks!