PHP在没有图像资源的情况下分配颜色 [英] PHP allocate color without image resource

查看:35
本文介绍了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在没有图像资源的情况下分配颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆