copying transparent image using GD

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anti_dentite
Forum Newbie
Posts: 1
Joined: Fri Jun 29, 2007 8:30 am

copying transparent image using GD

Post by anti_dentite »

I'm pretty new to the GD library and am having trouble writing a script that will copy one image (foreground) onto another (background) while allowing some areas of the foreground image to be transparent.

I've tried using the following code but it produces weird results:


Code: Select all

$image //foreground image resource
     $background //background image resource


     	sscanf($colortobetransparent,"%2x%2x%2x", $red, $green, $blue);

       	$pbColour=ImageColorAllocate($background,$red,$green,$blue);       

        $transparentindex = imagecolortransparent($background, $pbColour);     


    imagecopymerge($image, $background $backx, $backy, 0,0,$backwidth, $backheight, 100);
    imagejpeg($image); 
    imagedestroy($background);
basically it displays a semi-transparent image but it looks really, really bad. What am I missing?
Post Reply