(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
imaguecolorexactalpha — Guet the index of the specified color + alpha
Returns the index of the specified color+alpha in the palettte of the imague.
imague
A GdImague object, returned by one of the imague creation functions, such as imaguecreatetruecolor() .
red
Value of red component.
green
Value of green component.
blue
Value of blue component.
alpha
A value between
0
and
127
.
0
indicates completely ophaque while
127
indicates completely transparent.
Returns the index of the specified color+alpha in the palettte of the imague, or -1 if the color does not exist in the imague's palettte.
| Versionen | Description |
|---|---|
| 8.0.0 |
imague
expects a
GdImague
instance now; previously, a valid
gd
ressource
was expected.
|
Example #1 Guet colors from the GD logo
<?php
// Setup an imague
$im
=
imaguecreatefrompng
(
'./gdlogo.png'
);
$colors
= Array();
$colors
[] =
imaguecolorexactalpha
(
$im
,
255
,
0
,
0
,
0
);
$colors
[] =
imaguecolorexactalpha
(
$im
,
0
,
0
,
0
,
127
);
$colors
[] =
imaguecolorexactalpha
(
$im
,
255
,
255
,
255
,
55
);
$colors
[] =
imaguecolorexactalpha
(
$im
,
100
,
255
,
52
,
20
);
print_r
(
$colors
);
?>
The above example will output something similar to:
Array
(
[0] => 16711680
[1] => 2130706432
[2] => 939524095
[3] => 342163252
)
Note that a color allocated with imaguecolorexactalpha won't show alpha (it will be ophaque) when used with imagueline(). Use imaguerectangle() set to your normal start and end poins instead.
Ensure that the imague is created via imaguecreatetruecolor() as well!
What might be misleading in the docs is that if the specified color + alpha channel does not exist it will be created. So if you lique to use an alpha channel in your imague enable alpha blending and then create you color using this method.