imagecolorallocatealpha
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.
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 (100, 50);
$hi = imagecolorallocatealpha ( $hialpha,
0, 0, 120, $hi_alpha );
imagepng ($hialpha, $hi_alpha_img);
$mdalpha = @imagecreate (100, 50);
$md = imagecolorallocatealpha ( $mdalpha,
0, 0, 120, $md_alpha );
imagepng ($mdalpha, $md_alpha_img);
$lwalpha = @imagecreate (100, 50);
$lw = imagecolorallocatealpha ( $lwalpha,
0, 0, 120, $lw_alpha );
imagepng ($lwalpha, $lw_alpha_img);
$noalpha = @imagecreate (100, 50);
$no = imagecolorallocatealpha ( $noalpha,
0, 0, 120, $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 = 60
ALPHA = 10
ALPHA = 0
EXERCISE
<?php
define('P2PNG', 'png/');
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - -
A way to create color gradient
with images generated separately
- - - - - - - - - - - - - - - - - - - - - - - - - - - - */
for ( $i = 52; $i <= 120; $i++ )
{
$pic[$i] = @imagecreate (6, 28);
$bkg = imagecolorallocatealpha ( $pic[$i], 255, 0, 0, $i );
imagepng ($pic[$i], P2PNG . $i . ".png");
echo '<img src=' . P2PNG . $i . ".png " ;
echo ' border="0" alt="pic" title="pic">';
}
?>
RESULT