imagecolorallocatealpha 


gd apg

ALLOCATE a particular color for an image with a transparency.





This function ALLOCATE a particular color for an image with a transparency in $image.


PALETTE IMAGE

is the designation term for images with a small number of colors.

For this type of image, a maximum of 256 colors are accepted.


TRUECOLOR IMAGE

is the designation term for images with a great number of colors.

For this type of image, a maximum of 16,777,216 colors are accepted.





This function may return FALSE if the allocation failed, but may also return a non-Boolean value which evaluates to FALSE.

We recommed to use the operator === or var_dump for testing the returned value of this function.





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.


0 ≥ $red ≤ 255, 0 ≥ $green ≤ 255 & 0 ≥ $blue ≤ 255

or

0x00 ≥ $red ≤ 0xff, 0x00 ≥ $green ≤ 0xff & 0x00 ≥ $blue ≤ 0xff

or

0x00 ≥ $red ≤ 0xFF, 0x00 ≥ $green ≤ 0xFF & 0x00 ≥ $blue ≤ 0xFF



0 ≥ $alpha ≤ 127

where 0 indicates completely opaque while 127 indicates completely transparent.


<?php

int
|false imagecolorallocatealpha 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   


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 to determine the alpha to be applied to the color.



  1 EXERCISE   

<?php

$hi_alpha_img 
'png/PNG 007 01a.png';
$md_alpha_img 'png/PNG 007 01b.png';
$lw_alpha_img 'png/PNG 007 01c.png';
$no_alpha_img 'png/PNG 007 01d.png';
 
$hi_alpha 120;
$md_alpha 60;
$lw_alpha 10;
$no_alpha 0;

$hialpha = @imagecreate (10050);
$hi imagecolorallocatealpha $hialpha
                                
00120$hi_alpha  );
imagepng ($hialpha$hi_alpha_img);

$mdalpha = @imagecreate (10050);
$md imagecolorallocatealpha $mdalpha
                                
00120$md_alpha  );
imagepng ($mdalpha$md_alpha_img);

$lwalpha = @imagecreate (10050);
$lw imagecolorallocatealpha $lwalpha
                                
00120$lw_alpha  );
imagepng ($lwalpha$lw_alpha_img);

$noalpha = @imagecreate (10050);
$no imagecolorallocatealpha $noalpha
                                
00120$no_alpha );
imagepng ($noalpha$no_alpha_img);

?>
<?php 
echo 'ALPHA = ' $hi_alpha?><br> 
<img src="<?php echo 
                        
$hi_alpha_img?>" alt="hi"><br><br>

<?php echo 'ALPHA = ' $md_alpha?><br>
<img src="<?php echo 
                        
$md_alpha_img?>" alt="md"><br><br>

<?php echo 'ALPHA = ' $lw_alpha?><br>
<img src="<?php echo 
                       
$lw_alpha_img?>" alt="lw"><br><br>

<?php echo 'ALPHA = ' $no_alpha?><br>
<img src="<?php echo 
                       
$no_alpha_img?>" alt="no"><br>

 RESULT   

ALPHA = 120

alpha hi.png apr

ALPHA = 60

alpha md.png apr

ALPHA = 10

alpha lw.png apr

ALPHA = 0

alpha no.png apr

  2 EXERCISE   

<?php

define
('P2PNG''png/');

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    A way to create color gradient
    with images generated separately

   - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

for ( $i 52$i <= 120$i++ )
{

$pic[$i] = @imagecreate (628);
$bkg imagecolorallocatealpha $pic[$i], 25500$i );

imagepng ($pic[$i], P2PNG .  $i ".png");

echo 
'<img src=' P2PNG $i ".png " ;
echo 
' border="0" alt="pic" title="pic">';
}

?> 

 RESULT   

grad.png apr