note 85849 added to function.imagecolorat
| From: | Richard at osu1 dot php dot net | Date: | Sat, 20 Sep 2008 18:49:05 +0000 |
| Subject: | note 85849 added to function.imagecolorat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144576@lists.php.net to get a copy of this message | ||
With the following functions you can not only convert a 24 bit RGB integer to its corresponding red,
green, and blue values, but also 32 bit RGBA integers to its corresponding red, green, blue, and
ALPHA values.
Not only that, but I even threw in a function for converting those red, green, blue, and alpha
values back into a 32 bit RGBA integer.
Sample usage:
$int = rgba2int(255, 255, 255, 16);
echo $int . "<br>";
$rgba = int2rgba($int);
print_r($rgba);
What it should output:
285212671
Array
(
[r] => 255
[g] => 255
[b] => 255
[a] => 16
)
function rgba2int($r, $g, $b, $a=1) {
/*
This function builds a 32 bit integer from 4 values which must be 0-255 (8 bits)
Example 32 bit integer: 00100000010001000000100000010000
The first 8 bits define the alpha
The next 8 bits define the blue
The next 8 bits define the green
The next 8 bits define the red
*/
return ($a << 24) + ($b << 16) + ($g << 8) + $r;
}
function int2rgba($int) {
$a = ($int >> 24) & 0xFF;
$r = ($int >> 16) & 0xFF;
$g = ($int >> 8) & 0xFF;
$b = $int & 0xFF;
return array('r'=>$r, 'g'=>$g, 'b'=>$b,
'a'=>$a);
}
----
Server IP: 209.41.74.194
Probable Submitter: 69.232.203.169
----
Manual Page -- http://www.php.net/manual/en/function.imagecolorat.php
Edit -- https://master.php.net/note/edit/85849
Del: integrated -- https://master.php.net/note/delete/85849/integrated
Del: useless -- https://master.php.net/note/delete/85849/useless
Del: bad code -- https://master.php.net/note/delete/85849/bad+code
Del: spam -- https://master.php.net/note/delete/85849/spam
Del: non-english -- https://master.php.net/note/delete/85849/non-english
Del: in docs -- https://master.php.net/note/delete/85849/in+docs
Del: other reasons-- https://master.php.net/note/delete/85849
Reject -- https://master.php.net/note/reject/85849
Search -- https://master.php.net/manage/user-notes.php