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

PHP 教程 · 2019-01-31 09:58:37

imagecolorallocate — 为一幅图像分配颜色。

语法

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

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

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

注意:第一次对 imagecolorallocate() 的调用会给基于调色板的图像填充背景色,即用 imagecreate() 建立的图像。

实例

<?php
header("Content-type: image/png");
$im = @imagecreate(100, 50)
    or die("不能初始化新的 GD 图像流");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>

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

相关文章

  • imagecolorallocatealpha() 为一幅图像分配颜色和透明度。
  • imagecolordeallocate() 取消图像颜色的分配。

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Introduction to the Design and Analysis of Algorithms

Introduction to the Design and Analysis of Algorithms

Anany Levitin / Addison Wesley / 2006-2-24 / USD 122.00

Based on a Based on a new classification of algorithm design techniques and a clear delineation of analysis methods, "Introduction to the Design and Analysis of Algorithms" presents the subject in a c......一起来看看 《Introduction to the Design and Analysis of Algorithms》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

MD5 加密
MD5 加密

MD5 加密工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具