imagecolorexactalpha 


gd apg

GETS the index of the specified color plus alpha in the palette of the image.





This function get the index of an specific pixel color $image.





$image symbolized by a identifier returned by one of the image creation functions.


The red color value: 0 ≥ $red ≤ 255.

The green color value: 0 ≥ $green ≤ 255.

The blue color value: 0 ≥ $blue ≤ 255.


The alpha value: 0 ≥ $alpha ≤ 127, where 0 indicates completely opaque while 127 indicates completely transparent.


ALPHA-CHANNEL

or simply ALPHA, can be considered as the fourth component associated with color.

Basically, it interprets the transparency or opacity properties at the pixel level, including grayscale, especially in TRUECOLOR images, especially in PNG format.

This function may return the index of the specified color plus alpha in the palette of the image, or -1 if the color does not exist in the image's palette.



<?php

int imagecolorexactalpha 
GdImage $image
                                                     
int $red
                                                     
int $green
                                                     
int $blue
                                                     
int $alpha )


where,

$image An image identifier 

$red 
The value of red component of the color

$green 
The value of green component of the color

$blue 
The value of blue component of the color

$alpha 
The value of alpha

?>

  $image   


The image identifier.



  $red   


The value of red component of the color .



  $green   


The value of green component of the color.



  $blue   


The value of blue component of the color.



  $alpha   


The value to determine the alpha to be applied to the color.



  1 EXERCISE   

<?php

// RUN this code several times
 
echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

// $lang = 'pt';
$lang 'en';

$org_img "png/PNG 035 01 Nathan Phillips Sq.png";

$imorgimg imagecreatefrompng($org_img);
$nbr_c_o imagecolorstotal($imorgimg);

if(
$nbr_c_o == 0)
{
$pt '<br>IMAGEM TRUECOLOR ';
$en '<br>TRUECOLOR IMAGE ';
}
else
{
$pt ' IMAGEM PALETIZADA '$nbr_c_o .' cores ';
$en ' PALLETIZED IMAGE '$nbr_c_o .' colors ';
}
?>
<?php 
echo $org_img?><br><?php echo $$lang?><br><br>
<img src="<?php echo $org_img?>"
 alt="<?php echo $org_img?>
 title="<?php echo $org_img?>" width="400"><br><br>
 
 <?php
 $pal_ndx 
mt_rand(0526619192);
 
$pal_org "png/PNG 035 01 Nathan Phillips Sq-ndx.png";
 
$col_ndx imagecolorsforindex($imorgimg$pal_ndx);

$pt 'Índice da Paleta = ';
$en 'Palette Index = ';

echo $
$lang $pal_ndx
 
' <br><br><pre>';

print_r($col_ndx);

echo 
'</pre>';

$red $col_ndx['red'];
$green $col_ndx['green'];
$blue $col_ndx['blue'];
$alpha $col_ndx['alpha'];

$impalorg imagecreate(imagesx($imorgimg), 60);
imagecolorallocate($impalorg$red$green$blue);
imagepng($impalorg$pal_org);
?>

<br>
<?php echo $pal_org;

$pt "Cor: ";
$en "Color: ";

?>

<br><br><img src="<?php echo $pal_org?>" alt="<?php echo $pal_org?>" width="400" height="40"><br><br>
<?php
echo $$lang
 
' RGB = ( ' $red ', ' $green ', ' $blue ' ) ';
 
 
$exc_alpha imagecolorexactalpha($imorgimg,
                                                
$red$green$blue$alpha);
 
 
$pt 'Índice da paleta<sub>ex</sub>: ' $exc_alpha;
 
$en 'Palette index<sub>ex</sub>: ' $exc_alpha;
 echo 
'<br><br>' . $$lang ' ';

?> 


 RESULT   

PNG 035 01 Nathan Phillips Sq.png

EXISTING TRUECOLOR IMAGE

PNG 035 01 Nathan Phillips Sq.png apr

Palette Index = 189473990

Array
(
[red] => 75
[green] => 36
[blue] => 198
[alpha] => 11
)


PNG 035 01 Nathan Phillips Sq-ndx.png

PNG 035 01 Nathan Phillips Sq-ndx.png apr

Color: RGB = ( 75, 36, 198 )

Palette indexex: 189473990


This is a particular result given the use of the mt_rand function to designate the palette index.

Run multiple times to get different results.


  2 EXERCISE   

<?php
 
// RUN this code several times
 
echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

// $lang = 'pt';
$lang 'en';

$org_img02 "gif/GIF 017 01 Nathan Phillips Sq.gif";

$id_orgimg02 imagecreatefromgif($org_img02);
$nbr_c_o02 imagecolorstotal($id_orgimg02);

if(
$nbr_c_o02 == 0)
{
$pt '<br>IMAGEM TRUECOLOR ';
$en '<br>TRUECOLOR IMAGE ';
}
else
{
$pt '<br>IMAGEM PALETIZADA '$nbr_c_o02 .' cores ';
$en '<br>PALLETIZED IMAGE '$nbr_c_o02 .' colors ';
}
?>
<?php 
echo $org_img02?> <?php echo $$lang?><br><br>
<img src="<?php echo $org_img02?>"
 alt="<?php echo $org_img02?>
 title="<?php echo $org_img02?>" width="400"><br><br>
 
 <?php
 $pal_ndx02 
mt_rand(0252);
 
$pal_org02 "gif/GIF 017 01 Nathan Phillips Sq-ndx.gif";
 
$col_ndx imagecolorsforindex($id_orgimg02$pal_ndx02);

$pt 'Índice da Paleta = ';
$en 'Palette Index = ';

echo $
$lang $pal_ndx02
 
' <br><br><pre>';

print_r($col_ndx);

echo 
'</pre>';

$red02 $col_ndx['red'];
$green02 $col_ndx['green'];
$blue02 $col_ndx['blue'];
$alpha02 $col_ndx['alpha'];

$id_palorg02 imagecreate(imagesx($id_orgimg02), 30);

imagecolorallocate($id_palorg02$red02$green02$blue02);
                                
imagegif($id_palorg02$pal_org02);
?>

<br>
<?php echo $pal_org02;

$pt "Cor: ";
$en "Color: ";

?>

<br><br><img src="<?php echo $pal_org02?>" alt="<?php echo $pal_org02?>" width="400" height="40"><br><br>
<?php
echo $$lang
 
' RGB = ( ' $red02 ', ' $green02 ', ' $blue02 ' ) ';
 
 
$exc_alpha02 
 
imagecolorexactalpha($id_orgimg02
                                     
$red02$green02$blue02$alpha02);
 
 
$pt 'Índice da paleta<sub>ex</sub>: ' $exc_alpha02;
 
$en 'Palette index<sub>ex</sub>: ' $exc_alpha02;
 echo 
'<br><br>' . $$lang ' ';

?> 


 RESULT   

GIF 017 01 Nathan Phillips Sq.gif

EXISTING TRUECOLOR IMAGE

GIF 017 01 Nathan Phillips Sq.gif apr

Palette Index = 104

Array
(
[red] => 181
[green] => 15
[blue] => 68
[alpha] => 0
)


GIF 017 01 Nathan Phillips Sq-ndx.gif

GIF 017 01 Nathan Phillips Sq-ndx.gif apr

Color: RGB = ( 181, 15, 68 )

Palette indexex: 104


This is a particular result given the use of the mt_rand function to designate the palette index.

Run multiple times to get different results.