我試圖使用GD更改圖像的不透明度,幾乎所有解決方案都與下面的代碼類似,您在其中創建白色透明背景並將其與您的圖片。更改PHP中圖像的不透明度
但是這不會使圖像變得透明,圖像變得更亮,您實際上無法看透圖像。
所以我的問題是,如何更改圖像的不透明度,以便您可以查看它? 或者我在做這個代碼有問題嗎?
//Create an image with a white transparent background color
$newImage = ImageCreateTruecolor(300, 300);
$bg = ImageColorAllocateAlpha($newImage, 255, 255, 255, 127);
ImageFill($newImage, 0, 0, $bg);
//Get the image
$source = imagecreatefrompng('my_image.png');
$opacity = 50;
//Merge the image with the background
ImageCopyMerge($newImage,
$source,
0, 0, 0, 0,
300,
300,
$opacity);
header('Content-Type: image/png');
imagepng($newImage);
imagedestroy($newImage);
謝謝!
我不確定,但這只是一個不叫'imagealphablending'(或'imagesavealpha')的問題嗎? – abarnert
經過快速搜索,可能dup:http://stackoverflow.com/questions/5529306/i-cant-use-transparent-background-with-imagecopymerge – abarnert
你有沒有嘗試改變CSS的不透明度? – Nick