非常教程

PHP参考手册

PHP imagecolorallocatealpha – 为一幅图像分配颜色和透明度

PHP imagecolorallocatealpha – 为一幅图像分配颜色和透明度

PHP imagecolorallocatealpha - 为一幅图像分配颜色和透明度

PHP imagecolorallocatealpha – 为一幅图像分配颜色和透明度

PHP 图像处理

imagecolorallocatealpha — 为一幅图像分配颜色和透明度。

语法

int imagecolorallocatealpha ( resource $image , int $red , int $green , int $blue , int $alpha )

imagecolorallocatealpha() 的行为和 imagecolorallocate() 相同,但多了一个额外的透明度参数 alpha,其值从 0 到 127。0 表示完全不透明,127 表示完全透明。

如果分配失败则返回 FALSE。

注意:此函数需要 GD 2.0.1 或更高版本(推荐 2.0.28 及更高版本)。

实例

<?php
$size = 300;
$image=imagecreatetruecolor($size, $size);

// 用白色背景加黑色边框画个方框
$back = imagecolorallocate($image, 255, 255, 255);
$border = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back);
imagerectangle($image, 0, 0, $size - 1, $size - 1, $border);

$yellow_x = 100;
$yellow_y = 75;
$red_x    = 120;
$red_y    = 165;
$blue_x   = 187;
$blue_y   = 125;
$radius   = 150;

// 用 alpha 值分配一些颜色
$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
$red    = imagecolorallocatealpha($image, 255, 0, 0, 75);
$blue   = imagecolorallocatealpha($image, 0, 0, 255, 75);

// 画三个交迭的圆
imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow);
imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red);
imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue);

// 不要忘记输出正确的 header!
header('Content-type: image/png');

// 最后输出结果
imagepng($image);
imagedestroy($image);
?>

以上实例输出结果的图片如下:

PHP imagecolorallocatealpha – 为一幅图像分配颜色和透明度

相关文章

  • imagecolorallocate() 为一幅图像分配颜色。
  • imagecolordeallocate() 取消图像颜色的分配。

PHP imagecolorallocatealpha – 为一幅图像分配颜色和透明度

PHP 图像处理

PHP imagecolorallocatealpha – 为一幅图像分配颜色和透明度

PHP目录

1.PHP Error 和 Logging 函数
2.PHP 5 Directory 函数
3.PHP 5 Date/Time 函数
4.PHP 5 Calendar 函数
5.PHP 5 Array 函数
6.PHP 5 SimpleXML 函数
7.PHP 5 MySQLi 函数
8.PHP Misc. 函数
9.PHP 5 Math 函数
10.PHP Mail 函数
11.PHP Libxml 函数
12.PHP HTTP 函数
13.PHP FTP 函数
14.PHP Filter 函数
15.PHP 5 Filesystem 函数
16.PHP 简介
17.PHP 教程
18.PHP Zip File 函数
19.PHP XML 函数
20.PHP 5 String 函数
21.PHP 语法
22.PHP 安装
23.PHP If…Else 语句
24.PHP 运算符
25.PHP 字符串变量
26.PHP 变量
27.PHP 函数
28.PHP For 循环
29.PHP While 循环
30.PHP 数组排序
31.PHP 数组
32.PHP Switch 语句
33.PHP include 和 require
34.PHP date() 函数
35.PHP 安全 E-mail
36.PHP 邮件
37.PHP Session
38.PHP Cookie
39.PHP 文件
40.PHP 异常处理
41.PHP 错误处理
42.PHP MySQL 读取数据
43.PHP MySQL 插入数据
44.PHP MySQL 创建数据库
45.PHP MySQL 简介
46.PHP – AJAX 与 PHP
47.PHP XML SimpleXML
48.PHP XML DOM
49.PHP XML Expat 解析器
50.PHP 数据库 ODBC
51.PHP MySQL Delete
52.PHP MySQL Update
53.PHP MySQL Order By 关键词
54.PHP MySQL Where 子句
55.PHP 实例 AJAX 投票
56.PHP 实例 AJAX RSS 阅读器
57.PHP 实例 AJAX 实时搜索
58.PHP 实例 AJAX 与 XML
59.PHP 实例 AJAX 与 MySQL
60.PHP array() 函数
61.PHP 5 Timezones
62.PHP array_fill() 函数
63.PHP array_diff_ukey() 函数
64.PHP array_diff_uassoc() 函数
65.PHP array_diff_key() 函数
66.PHP array_diff_assoc() 函数
67.PHP array_diff() 函数
68.PHP array_count_values() 函数
69.PHP array_combine() 函数
70.PHP array_chunk() 函数
71.PHP array_change_key_case() 函数
72.PHP array_key_exists() 函数
73.PHP array_intersect_ukey() 函数
74.PHP array_intersect_uassoc() 函数
75.PHP array_intersect_key() 函数
76.PHP array_intersect_assoc() 函数
77.PHP array_intersect() 函数
78.PHP array_flip() 函数
79.PHP array_filter() 函数
80.PHP array_fill_keys() 函数
81.PHP array_map() 函数
82.PHP array_keys() 函数
83.PHP array_reduce() 函数
84.PHP array_rand() 函数
85.PHP array_push() 函数
86.PHP array_product() 函数
87.PHP array_pop() 函数
88.PHP array_pad() 函数
89.PHP array_multisort() 函数
90.PHP array_merge_recursive() 函数
91.PHP array_merge() 函数
92.PHP array_uintersect() 函数
93.PHP array_udiff_uassoc() 函数
94.PHP array_udiff_assoc() 函数
95.PHP array_udiff() 函数
96.PHP array_sum() 函数
97.PHP array_splice() 函数
98.PHP array_slice() 函数
99.PHP array_shift() 函数
100.PHP array_search() 函数