PHP 中的 imagecolorallocatealpha() 函数
imagecolorallocatealpha() 函数用于为图像分配颜色。
语法
imagecolorallocatealpha ( img, red, green, blue, alpha )
参数
img: 使用 imagecreatetruecolor() 创建的图像资源。
red: 红色颜色组件
green: 绿色颜色组件
blue: 蓝色颜色组件
alpha: 图像的透明度,0 表示完全不透明,而 127 表示完全透明。
返回值
imagecolorallocatealpha() 函数返回颜色标识符,如果分配失败,则返回 FALSE。
示例
以下是一个示例
<?php
$img = imagecreatetruecolor(520, 350);
$bgcolor = imagecolorallocate($img, 50, 10, 255);
imagefill($img, 0, 0, $bgcolor);
$one = imagecolorallocatealpha($img, 50, 255, 0, 70);
$two = imagecolorallocatealpha($img, 255, 0, 255, 50);
$three = imagecolorallocatealpha($img, 150, 255, 0, 60);
$four = imagecolorallocatealpha($img, 200, 0, 255, 90);
imagefilledellipse($img, 200, 150, 150, 150, $one);
imagefilledellipse($img, 220, 150, 150, 150, $two);
imagefilledellipse($img, 240, 150, 150, 150, $three);
imagefilledellipse($img, 280, 150, 150, 150, $four);
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>输出
以下为输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP