牛牛在线工具

imagealphablending()

收录 8868 个 PHP 函数,含用途说明与用法示例。

imagealphablending()

设置图像的混合模式,用于启用或禁用图像的 alpha 混合

函数名称:imagealphablending() 适用版本:PHP 4, PHP 5, PHP 7 函数描述:imagealphablending() 函数设置图像的混合模式,用于启用或禁用图像的 alpha 混合。 语法:bool imagealphablending ( resource $image , bool $blendmode ) 参数: $image:一个图像资源,使用 imagecreatetruecolor() 或 imagecreatefrom*() 函数创建。 $blendmode:一个布尔值,用于设置混合模式。若为 true,则启用 alpha 混合;若为 false,则禁用 alpha 混合。 返回值: 成功时,返回 true。 失败时,返回 false。 示例: // 创建一个新的图像资源 $image = imagecreatetruecolor(200, 200); // 设置混合模式为启用 alpha 混合 imagealphablending($image, true); // 为图像创建一个背景颜色 $backgroundColor = imagecolorallocate($image, 255, 255, 255); // 为图像创建一个半透明的矩形 $rectangleColor = imagecolorallocatealpha($image, 255, 0, 0, 75); imagefilledrectangle($image, 50, 50, 150, 150, $rectangleColor); // 输出图像 header('Content-type: image/png'); imagepng($image); imagedestroy($image); 上述示例中,我们创建了一个新的图像资源,并设置了混合模式为启用 alpha 混合。然后,我们使用 imagecolorallocate() 函数为图像创建一个背景颜色,并使用 imagecolorallocatealpha() 函数创建一个半透明的矩形。最后,我们输出图像并销毁资源。通过启用 alpha 混合,我们可以在图像中实现半透明效果。