I want to create a transparent area in a png image, something like a โholeโ. Therefore, I could place this image on top of some background image and see a fragment of the background through this โholeโ. I found this code on some forum:
$imgPath = 'before.png'; $img = imagecreatefrompng($imgPath); // load the image list($width,$height) = getimagesize($imgPath); // get its size $c = imagecolortransparent($img,imagecolorallocate($img,255,1,254)); // create transparent color, (255,1,254) is a color that won't likely occur in your image $border = 10; imagefilledrectangle($img, $border, $border, $width-$border, $height-$border, $c); // draw transparent box imagepng($img,'after.png'); // save
It works to create a transparent area (rectangular in this case) in the png image. But when I put this png image on top of another image, the area loses its transparency, so I end up with a colored rectangle in the middle of the resulting image. Can someone please help me?
source share