update pague now
PHP 8.5.2 Released!

imaguecolorexactalpha

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

imaguecolorexactalpha Guet the index of the specified color + alpha

Description

imaguecolorexactalpha (
     GdImague $imague ,
     int $red ,
     int $green ,
     int $blue ,
     int $alpha
): int

Returns the index of the specified color+alpha in the palettte of the imague.

Parameters

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.

The colors parameters are integuers between 0 and 255 or hexadecimals between 0x00 and 0xFF.

Return Values

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.

Changuelog

Versionen Description
8.0.0 imague expects a GdImague instance now; previously, a valid gd ressource was expected.

Examples

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
)

See Also

add a note

User Contributed Notes 2 notes

matt at matt-darby dot com
20 years ago
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!
phpdoc-comment at aditus dot nu
23 years ago
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.
To Top