PNG画像に透明な領域、ある種の「穴」を作成したい。したがって、この画像を背景画像の上に配置すると、その「穴」から背景の断片を見ることができます。フォーラムでこのコードを見つけました:
$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
PNG画像に透明領域(この場合は長方形)を作成するために機能します。しかし、この png 画像を他の画像の上に配置すると、その領域の透明度が失われるため、結果の画像の中央に色付きの四角形ができてしまいます。誰か助けてくれませんか?