问题描述
您可以在,而没有?这应该是可能的,因为真正分配的颜色是一个数字,对吧?
$ 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
strong>
我猜想真正的问题是如何将255,0和0变成16711680.
16711680(十进制)为0x00FF0000(十六进制)
00 - Alpha值b
FF - 红色(255分十二)
00 - 绿色(0十分)
00 - Blue(0 dec)
请参阅以设置Alpha字节
编辑:
此外,要回答第一个问题 - 是,您可以创建不含图片资源的颜色调用imagecolorallocate):
$ col1 = 0x00FF0000; // Red
$ col2 = 0x0000FF00; // Green
// etc ...
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;
This prints out:
16711680
16711680
16711680
I guess what the real question is how 255, 0, and 0 are made into 16711680.
16711680 (decimal) is 0x00FF0000 (hexadecimal)
00 - Alpha value (0 dec)
FF - Red (255 dec)
00 - Green (0 dec)
00 - Blue (0 dec)
See http://www.php.net/manual/en/function.imagecolorallocatealpha.php to set the alpha byte
Edit:
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; // Red
$col2 = 0x0000FF00; // Green
// etc...
这篇关于PHP分配颜色而没有图像资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!