Page 1 of 1

imagecopy() with PNG alpha transparency?

Posted: Wed Jun 18, 2008 1:03 am
by Josh1billion
I am trying to generate an image out of two images. I have a background image, and then an object image. The object image is drawn onto the background image. The object image's background should be transparent so that the "background image" can show through after the drawing.

Is there a way to do this with PNG's built-in transparency, rather than using the set transparency function?

Re: imagecopy() with PNG alpha transparency?

Posted: Wed Jun 18, 2008 1:15 am
by Josh1billion
Nevermind, got it! A good hour or two of frustration is finally over!

Solution:

I changed my imagecopymerge() function to imagecopy() instead (and removed the last argument which isn't used in imagecopy()).

Re: imagecopy() with PNG alpha transparency?

Posted: Wed Jun 18, 2008 2:33 am
by onion2k
It can be done with imagecopy() too.. you just need to make sure the imagesavealpha() and imagealphablending() values are correct for both images.

Re: imagecopy() with PNG alpha transparency?

Posted: Wed Jun 18, 2008 5:12 pm
by Josh1billion
What I meant was that I was originally trying to use imagecopymerge(), and the solution was to change that to imagecopy() instead.

Re: imagecopy() with PNG alpha transparency?

Posted: Mon Sep 29, 2008 7:00 am
by sneha1234
hi!
i m facing the same Problem i want transparent image of some width n height and text on that image...but when i m using imageSaveAlpha($image, true);
ImageAlphaBlending($image, false); its not working...

<?php

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

//$size = 300;
//$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);
?>
then i m getting diminished text....