超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<imagecharupimagecolorallocatealpha>
Last updated: Fri, 22 Jun 2007

imagecolorallocate

(PHP 3, PHP 4 , PHP 5)

imagecolorallocate -- 为一幅图像分配颜色

说明

int imagecolorallocate ( resource image, int red, int green, int blue)

imagecolorallocate() 返回一个标识符,代表了由给定的 RGB 成分组成的颜色。image 参数是 imagecreate() 函数的返回值。redgreenblue 分别是所需要的颜色的红,绿,蓝成分。这些参数是 0 到 255 的整数或者十六进制的 0x00 到 0xFF。imagecolorallocate() 必须被调用以创建每一种用在 image 所代表的图像中的颜色。

注: 第一个对 imagecolorallocate() 的调用填充背景色。

<?php

// 背景设为红色
$background = imagecolorallocate($im, 255, 0, 0);

// 设定一些颜色
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// 十六进制方式
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);

?>

如果分配失败则返回 -1。

参见 imagecolorallocatealpha()imagecolordeallocate()




add a note add a note User Contributed Notes
imagecolorallocate
doiveo at hotmail dot nospam
12-Jan-2002 02:17
This will help anyone trying to control font colors in a JPEG. You have to create a temporary image first, allocate the colors then merge the images before it works. Go figure.

$im_size = GetImageSize ( "MySource.jpg" );
$imageWidth = $im_size[0];
$imageHeight = $im_size[1];

$im = imageCreate( $imageWidth, $imageHeight );

// - or with GD 2+ -
// $im = imageCreateTrueColor( $imageWidth, $imageHeight );

// do all your color allocations here
$font_color_black = ImageColorAllocate( $im, 0,0,0);

$im2 = ImageCreateFromJPEG("MySource.jpg");

ImageCopy ($im,$im2,0,0,0,0, $imageWidth, $imageHeight);
ImageDestroy ($im2);

...finish as you please using the $im var.

<imagecharupimagecolorallocatealpha>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22