Forum Moderators: coopster

Message Too Old, No Replies

imagecopymerge( ) function

need help combining images with alphas

         

willis1480

8:47 pm on Aug 25, 2008 (gmt 0)

10+ Year Member



I need to be able to combine images with gradiant alphas, but it seems that imagecopymerge removes the alphas.

According to PHP manual this should be the function used to combine images while maintaining the alpha.

Here is code (new to GD, so this may be all wrong):
<?php
$txt = $_GET['text'];
header("Content-type: image/png");
$image = imagecreatetruecolor(110, 30);

$transparentColor = imagecolorallocatealpha($image, 200, 200, 200, 127);
imagefill($image, 0, 0, $transparentColor);

imageSaveAlpha($image, true);
ImageAlphaBlending($image, false);

$bgimage = imagecreatefrompng("button_grad.png");
imageSaveAlpha($bgimage, true);
imageAlphaBlending($bgimage, false);

imagecopymerge($image,$bgimage,0,0,0,0,110,30,0);

$text_color = imagecolorallocate($image, 0, 0, 0);

imagestring($image, 1, 5, 5, $txt, $text_color);

imagepng($bgimage);
imagedestroy($image);
imagedestroy($bgimage);
?>

***All I get is a grey image.

willis1480

9:00 pm on Aug 25, 2008 (gmt 0)

10+ Year Member



Well, after messing with this and looking around there was just one piece messed up, I guess you use imagecopy() and NOT imagecopymerge()...I would have sworn PHP manual said to use imagecopymerge for alphas.

Misunderstood this line in the imagecopymerge:
The two images will be merged according to pct which can range from 0 to 100. When pct = 0, no action is taken, when 100 this function behaves identically to imagecopy() for pallete images, while it implements alpha transparency for true colour images.