【发布时间】:2012-03-19 20:47:31
【问题描述】:
这是我的问题:
我想通过将图像复制到另一个透明图像上来更改图像的不透明度。
我的代码:
$opacity = 50;
$transparentImage = imagecreatetruecolor($width, $height);
imagesavealpha($transparentImage, true);
$transColour = imagecolorallocatealpha($transparentImage , 0, 0, 0, 127);
imagefill($transparentImage , 0, 0, $transColour);
imagecopymerge($transparentImage, $image, 0, 0, 0, 0, $width, $height, $opacity);
$image = $transparentImage;
header('Content-type: image/png');
imagepng($image);
通过这样做,当我使用 imagecopymerge 时,$transparentImage 会失去透明度...因此 $image 会合并到黑色图像上...而不是透明图像上!
但是,当我在调用 imagecopymerge 之前显示 $transparentImage 时,图像在我的导航器中是透明的!
有没有办法改变我的图像的不透明度,而不在彩色背景上添加它?
【问题讨论】:
标签: php image transparency opacity