imagecolorallocate - 分配一个彩色的图像
int imagecolorallocate(resource $image,int $red,int $green,int $blue)
返回一个颜色标识代表给定的RGB成分组成的颜色,imagecolorallocate()必须被调用来创建每个颜色,将在由形象代表的图像中使用.
第一次调用imagecolorallocate()填补了调色板背景颜色的图像 - 图像创建使用imagecreate().
图片: 图像资源,通过创造的图像功能,如,一返回imagecreatetruecolor().
红色:红色分量的价值。
绿色:价值的绿色成分。
蓝色:蓝色成分的价值。
这些参数是介于0和255之间或0x00和0xFF十六进制整数。
报告错误返回值,阿色标识或FALSE如果分配失败.
<?php $im = imagecreate(100, 100); // sets background to red $background = imagecolorallocate( $im , 255, 0, 0); // sets some colors $white = imagecolorallocate( $im , 255, 255, 255); $black = imagecolorallocate( $im , 0, 0, 0); // hexadecimal way $white = imagecolorallocate( $im , 0xFF, 0xFF, 0xFF); $black = imagecolorallocate( $im , 0x00, 0x00, 0x00); //开源代码phpfensi.com ?>这里有一个非常简单的函数,基本上是相同imagecolorallocate(),而无需只有一个,图像资源工作,实例代码如下:
<?php function createcolor( $r , $g , $b ) { return hexdec( str_pad ( dechex ( $r ), 2, 0, STR_PAD_LEFT). str_pad ( dechex ( $g ), 2, 0, STR_PAD_LEFT). str_pad ( dechex ( $b ), 2, 0, STR_PAD_LEFT)); } / *正如前面所说的,这个函数不完全一样的事情作为imagecolorallocate(),而不 需要一个图像资源。这意味着,下面的两个区块中的代码的结果完全相同的事情:* / $color = colorcreate(105, 199, 204); //Block 2 $img = imagecreatetruecolor(100, 100); //the arguments here don't really matter $color = imagecolorallocate( $img , 105, 199, 204); imagedestroy( $img ); ?>
查看更多关于php imagecolorallocate的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did29464