imagecolortransparent() 函数在 PHP 中用于设置图像资源中颜色的透明度
int imagecolortransparent ( resource $image [, int $color = -1 ] )参数说明:
$image:必需。规定要使用的图像资源。这是一个由 imagecreatefrom* 函数(如 imagecreatefrompng())创建的图像资源。$color:可选。规定要设置为透明的颜色。如果未指定此参数,则返回当前透明色。返回值:
成功时返回透明颜色的索引,失败时返回 -1。示例:
<?php// 创建一个新的空白图像$image = imagecreatetruecolor(100, 100);// 分配颜色$red = imagecolorallocate($image, 255, 0, 0);$blue = imagecolorallocate($image, 0, 0, 255);// 设置红色为透明imagecolortransparent($image, $red);// 使用透明颜色绘制一个矩形imagerectangle($image, 20, 20, 80, 80, $red);// 输出图像header("Content-type: image/png");imagepng($image);// 销毁图像资源imagedestroy($image);?>在这个示例中,我们创建了一个 100x100 的空白图像,并分配了红色和蓝色。然后,我们将红色设置为透明,并使用透明颜色绘制一个矩形。最后,我们输出图像并销毁图像资源。


