PHP 中的 imagecolorallocate() 函数


imagecolorallocate() 函数为图像分配颜色。

语法

int imagecolorallocate ( $img, $red, $green, $blue )

参数

  • img: 使用 imagecreatetruecolor() 创建的图像资源。

  • red: 红色颜色分量

  • green: 绿色颜色分量

  • blue: 蓝色颜色分量

返回

imagecolorallocate() 函数返回 RGB 格式的颜色。

示例

以下是一个示例

<?php
   $img = imagecreatetruecolor(600, 220);
   $bgcolor = imagecolorallocate($img, 20, 50, 120);
   imagefill($img, 0, 0, $bgcolor);
   header("Content-type: image/png");
   imagepng($img);
   imagedestroy($img);
?>

输出

以下是输出

更新于: 31-Dec-2019

487 浏览量

开启你的职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.