PHP allocate color without image resource(PHP在没有图像资源的情况下分配颜色)
问题描述
你能在PHP GD中分配颜色吗a> 没有 图像资源?这应该是可能的,因为分配的颜色实际上是一个数字,对吗?
Can you allocate a color in PHP GD without an image resource? It should be possible because really an allocated color is a number, right?
$im = imagecreatetruecolor(100, 100);
$col = imagecolorallocate($im, 255, 0, 0);
print $col."<br/>";
$col2 = imagecolorallocate($im, 255, 0, 0);
print $col2."<br/>";
$im2 = imagecreatetruecolor(600, 100);
$col3 = imagecolorallocate($im, 255, 0, 0);
print $col3;
打印出来:
16711680
16711680
16711680
我想真正的问题是如何将 255、0 和 0 变成 16711680.
I guess what the real question is how 255, 0, and 0 are made into 16711680.
推荐答案
16711680(十进制)为 0x00FF0000(十六进制)
16711680 (decimal) is 0x00FF0000 (hexadecimal)
00 - Alpha 值 (0 dec)
00 - Alpha value (0 dec)
FF - 红色(255 dec)
FF - Red (255 dec)
00 - 绿色(0 dec)
00 - Green (0 dec)
00 - 蓝色 (0 dec)
00 - Blue (0 dec)
参见 http://www.php.net/manual/en/function.imagecolorallocatealpha.php 设置 alpha 字节
See http://www.php.net/manual/en/function.imagecolorallocatealpha.php to set the alpha byte
此外,要回答您的第一个问题 -- 是,您可以在没有图像资源的情况下创建颜色(因此无需调用 imagecolorallocate):
Also, to answer your first question -- yes, you can create a color without an image resource (and, consequently without a call to imagecolorallocate):
$col1 = 0x00FF0000;//红色
$col1 = 0x00FF0000; // Red
$col2 = 0x0000FF00;//绿色
$col2 = 0x0000FF00; // Green
//等等...
这篇关于PHP在没有图像资源的情况下分配颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP在没有图像资源的情况下分配颜色
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
