我已成功地將一個PNG圖像合併到使用PHP GD庫的JPEG背景,但是我希望PNG圖像具有透明背景,但白色背景不斷顯示爲如下圖所示:php將透明PNG圖像合併到jpeg防止白色背景
我已經看了幾個帖子,以解決此問題,並試圖一切都是徒勞的實現方法的不同,任何建議,我應該添加或做什麼?
這裏是我的代碼:
<?php
$background = imagecreatefromjpeg('img3.jpg');
$bird = imagecreatefrompng('img4.png');
$bird_x = imagesx($bird);
$bird_y = imagesy($bird);
imagesavealpha($bird, true);
$color = imagecolorallocatealpha($bird, 0, 0, 0, 127);
imagefill($bird, 0, 0, $color);
if (imagecopymerge($background, $bird, 0, 0, 0, 0, $bird_x, $bird_y, 100))
{
header('Content-Type: image/jpeg');
imagejpeg($background);
imagedestroy($bird);
}
else
{
header('Content-Type: text/html');
echo "Failed to Merge images!";
}
?>
添加一些代碼樣本這裏 – Elby