2
我有一個包含透明度的圖像,我正在與其他圖像(在php中創建)合併,並添加一些文本。目前的透明度似乎工作,但它使後面的背景透明,留下一個大缺口形象:合併圖像並保留透明度
//creates a image handle
$img = imagecreate(500, 200);
$logo = imagecreatefrompng('logo.png');// <--- logo with transparent background, png24 from photoshop
imagealphablending($logo, true);
imagesavealpha($logo, true);
//choose a bg color, u can play with the rgb values
$background = imagecolorallocate($img, 173, 184, 194);
//chooses the text color
$text_colour = imagecolorallocate($img, 255, 255, 255);
//sets the thickness/bolness of the line
imagesetthickness ($img, 3);
//pulls the value passed in the URL
$text = $_GET['name'];
$pos = $_GET['title'];
// place the font file in the same dir level as the php file
$font = 'NeutraText-BoldAlt.ttf';
//this function sets the font size, places to the co-ords
imagettftext($img, 30, 0, 11, 128, $text_colour, $font, $text);
//places another text with smaller size
imagettftext($img, 16, 0, 10, 155, $text_colour, $font, $pos);
// PUC
imagettftext($img, 16, 0, 10, 180, $text_colour, $font, "My Organization");
// fix trans
imagealphablending($img, false);
imagesavealpha($img, true);
// Merge the images
imagecopyresampled($img, $logo, 10, 10, 0, 0, 150, 78, 150, 78);
//alerts the browser abt the type of content i.e. png image
header('Content-type: image/png');
//now creates the image
imagepng($img);
//destroys used resources
imagecolordeallocate($text_color);
imagecolordeallocate($background);
imagedestroy($img);
什麼我需要做的維護$標誌的透明度,當加入到$ IMG ?