开发者

PHP: work with colors directly without imagecolorallocate?

开发者 https://www.devze.com 2023-01-18 06:02 出处:网络
After working with a lot of GD recently (for some fairly large scale projects for work) I had been dealing with RGB codes that I am not so accustomed to.

After working with a lot of GD recently (for some fairly large scale projects for work) I had been dealing with RGB codes that I am not so accustomed to.

My co-workers and I had been suffering some what to find a good method to do this without resorting to a makeshift 'hex to rgb' function with arrays for just a simple function.

There must开发者_JAVA技巧 be a way?


If I am aware imagecolorallocate() only returns a hex representation to be used by the other GD functions, as the library is a bit lower level than PHP of course it works with hex values directly, so there raised a need for an intermediate function to assign a colour.

The following should be equivalent:

$im = imagecreatetruecolor("200", "100");
$white = imagecolorallocate($im, 255, 255, 255);
$white = 0x00FFFFFF;
$alphagreen = imagecolorallocatealpha($im, 0, 255, 0, 64); 
$alphagreen = 0x4000FF00;
0

精彩评论

暂无评论...
验证码 换一张
取 消