PHP 中的 imagecolortransparent() 函数

phpserver side programmingprogramming

imagecolortransparent() 函数用于设置透明图像的颜色。

语法

imagecolortransparent ( img, color )

参数

  • img:使用 imagecreatetruecolor() 函数创建图像。

  • color:使用 imagecolorallocate() 创建的颜色标识符。

返回

imagecolortransparent() 函数返回新的透明颜色标识符。如果未指定 color 且图像没有透明颜色,则返回值为 -1。

示例

以下是示例

<?php
   $img = imagecreatetruecolor(500, 400);
   $blue = imagecolorallocate($img, 0, 0, 255);
   $transparent = imagecolorallocate($img, 0, 0, 0);
   imagecolortransparent($img, $transparent);
   imagefilledrectangle($img, 80, 90, 400, 220, $blue);
   header('Content-Type: image/png');
   imagepng($img);
   imagedestroy($img);
?>

输出

输出结果如下:


相关文章