imagesavealpha 


gd apg

ALLOW to decide whether or not the alpha effect should be retained when PNG image files are saved.





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





$image symbolized by a identifier returned by one of the image creation functions, such as imagecreatetruecolor.

This function sets the flag which determines whether to retain full alpha channel information, (as opposed to single-color transparency), when saving PNG images.

If $enable = FALSE the alpha-channel is not retained.

If $enable = TRUE the alpha-channel is retained.

This function returns TRUE on success or FALSE on failure.


ALPHA-CHANNEL

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

Basically interprets pixel-level transparency or opacity properties, including grayscale, especially for TRUECOLOR images in PNG format.



<?php

bool imagesavealpha
(GdImage $imagebool $enable)

where,

$image An image identifier

$enable 
To decide if the alpha channel will be retained or not

?>

  $image   


The image identifier.



  $enable   


To decide if the alpha channel will be retained or not.



  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$lang 'en';

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

$dst_img01a "png/PNG 035 01 Nathan Phillips Sq no alpaha.png";

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

$id_org_img01 imagecreatefrompng($org_img01);
$nbr_colors_org_img01 imagecolorstotal($id_org_img01);

if(
$nbr_colors_org_img01 == 0)
{
$en '<br>TRUECOLOR IMAGE';
}
else
{
$en 'PALLETIZED IMAGE '$nbr_colors_org_img01 .' colors';
}

echo 
$org_img01?><?php echo $$lang?><br><br>
<img src="<?php echo $org_img01?>"
 alt="<?php echo $org_img01?>
 title="<?php echo $org_img01?>" width="400"><br><br> 
 
<?php

$id_org_img01 
imagecreatefrompng($org_img01);

$save_flag01 0;

$save_alpha01 imagesavealpha ($id_org_img01$save_flag01);
imagepng($id_org_img01$dst_img01a);

echo 
$dst_img01a?> <?php echo '<br>save flag = ' 
$save_flag01?><br><br>
<img src="<?php echo $dst_img01a?>"
 alt="<?php echo $dst_img01a?>
 title="<?php echo $dst_img01a?>" width="400"><br><br>
  
 <?php

$id_org_img02 
imagecreatefrompng($org_img01);

$save_flag02 1;

$save_alpha02 imagesavealpha ($id_org_img02$save_flag02);
imagepng($id_org_img02$dst_img01b);

echo 
$dst_img01b?> <?php echo '<br>save flag = ' 
$save_flag02?><br><br>
<img src="<?php echo $dst_img01b?>"
 alt="<?php echo $dst_img01b?>
 title="<?php echo $dst_img01b?>" width="400"><br> 
 
 

 RESULT   

PNG 035 01 Nathan Phillips Sq.png

TRUECOLOR IMAGE

PNG 035 01 Nathan Phillips Sq.png apr

PNG 035 01 Nathan Phillips Sq no alpaha.png

save flag = 0
ALPHA-CHANNEL IS NOT RETAINED


PNG 035 01 Nathan Phillips Sq no alpaha.png apr

PNG 035 01 Nathan Phillips Sq alpha.png

save flag = 1
ALPHA-CHANNEL IS RETAINED


PNG 035 01 Nathan Phillips Sq alpha.png apr

  2 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$lang 'en';

$org_img02 "png/PNG 036 02 pomegranate.png";

$dst_img02a "png/PNG 036 02 pomegranate no alpaha.png";

$dst_img02b "png/PNG 036 02 pomegranate alpaha.png";

$id_org_img02 imagecreatefrompng($org_img02);
$nbr_colors_org_img02 imagecolorstotal($id_org_img02);

if(
$nbr_colors_org_img02 == 0)
{
$en '<br>TRUECOLOR IMAGE';
}
else
{
$en 'PALLETIZED IMAGE '$nbr_colors_org_img02 .' 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

$id_org_img02 
imagecreatefrompng($org_img02);

$save_flag02 0;

$save_alpha02 imagesavealpha ($id_org_img02$save_flag02);
imagepng($id_org_img02$dst_img02a);

echo 
$dst_img02a?> <?php echo '<br>save flag = ' 
$save_flag02?><br><br>
<img src="<?php echo $dst_img02a?>"
 alt="<?php echo $dst_img02a?>
 title="<?php echo $dst_img02a?>" width="400"><br><br>
  
 <?php

$id_org_img03 
imagecreatefrompng($org_img02);

$save_flag03 1;

$save_alpha03 imagesavealpha ($id_org_img03$save_flag03);
imagepng($id_org_img03$dst_img02b);

echo 
$dst_img02b?> <?php echo '<br>save flag = ' 
$save_flag03?><br><br>
<img src="<?php echo $dst_img02b?>"
 alt="<?php echo $dst_img02b?>
 title="<?php echo $dst_img02b?>" width="400"><br>
 
 

 RESULT   

PNG 036 02 pomegranate.png

TRUECOLOR IMAGE

PNG 036 02 pomegranate.png apr

PNG 036 02 pomegranate no alpaha.png

save flag = 0
ALPHA-CHANNEL IS NOT RETAINED


PNG 036 02 pomegranate no alpaha.png apr

056 01 PNG 036 02 pomegranate alpaha.png

save flag = 1
ALPHA-CHANNEL IS RETAINED


PNG 036 02 pomegranate alpaha.png apr

  3 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$lang 'en';

$org_img03 "gif/GIF 016 03 flowers.gif";

$dst_img03a "gif/GIF 016 03 flowers no alpha.gif";

$dst_img03b "gif/GIF 016 03 flowers alpha.gif";

$id_org_img03 imagecreatefromgif($org_img03);
$nbr_colors_org_img03 imagecolorstotal($id_org_img03);

if(
$nbr_colors_org_img03 == 0)
{
$en '<br>TRUECOLOR IMAGE';
}
else
{
$en '<br>PALLETIZED IMAGE<br>'
$nbr_colors_org_img03 .' colors';
}
?> 

<?php echo $org_img03?><?php echo $$lang?><br><br>
<img src="<?php echo $org_img03?>"
 alt="<?php echo $org_img03?>
 title="<?php echo $org_img03?>"><br><br> 
 
<?php

$id_org_img03 
imagecreatefromgif($org_img03);

$save_flag03 0;

$save_alpha03 imagesavealpha ($id_org_img03
                                                       
$save_flag03);
imagegif($id_org_img03$dst_img03a);

echo 
$dst_img03a?> 
<?php echo '<br>save flag = ' $save_flag03?><br><br>
<img src="<?php echo $dst_img03a?>"
 alt="<?php echo $dst_img03a?>
 title="<?php echo $dst_img03a?>"><br><br>
  
 <?php

$id_org_img04 
imagecreatefromgif($org_img03);

$save_flag04 1;

$save_alpha04 imagesavealpha ($id_org_img04
                                                       
$save_flag04);
imagegif($id_org_img04$dst_img03b);

echo 
$dst_img03b?> 
<?php echo '<br>save flag = ' $save_flag04?><br><br>
<img src="<?php echo $dst_img03b?>"
 alt="<?php echo $dst_img03b?>
 title="<?php echo $dst_img03b?>"><br>
 
 

 RESULT   

GIF 016 03 flowers.gif

PALETTE IMAGE
251 colors


GIF 016 03 flowers.gif apr

GIF 016 03 flowers no alpha.gif

save flag = 0
ALPHA-CHANNEL IS NOT RETAINED


GIF 016 03 flowers no alpha.gif apr

GIF 016 03 flowers alpha.gif

save flag = 1
ALPHA-CHANNEL IS RETAINED


GIF 016 03 flowers alpha.gif apr