|
|
 |
imagecolorallocate (PHP 3, PHP 4 , PHP 5) imagecolorallocate -- 为一幅图像分配颜色 说明int imagecolorallocate ( resource image, int red, int green, int blue)
imagecolorallocate() 返回一个标识符,代表了由给定的
RGB 成分组成的颜色。image
参数是 imagecreate()
函数的返回值。red,green 和
blue 分别是所需要的颜色的红,绿,蓝成分。这些参数是
0 到 255 的整数或者十六进制的 0x00 到 0xFF。imagecolorallocate()
必须被调用以创建每一种用在 image 所代表的图像中的颜色。
注:
第一个对 imagecolorallocate() 的调用填充背景色。
如果分配失败则返回 -1。
参见 imagecolorallocatealpha() 和
imagecolordeallocate()。
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.
| |