PHP 中的 imagecolortransparent() 函数


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);
?>

输出

以下为输出

更新时间: 31-Dec-2019

286 次浏览

提升你的职业生涯

完成课程即可获得认证

开始学习
广告
© . All rights reserved.