imagealphablending 


gd apg

SET the blending mode for an image.





This function allows for two different modes of drawing on truecolor images. In blending mode, the alpha channel component of the color supplied to all drawing function, such as imagesetpixel determines how much of the underlying color should be allowed to shine through.

As a result, GD automatically blends the existing color at that point with the drawing color, and stores the result in the image.

The resulting pixel is opaque.

In non-blending mode, the drawing color is copied literally with its alpha channel information, replacing the destination pixel.

If the $enable = TRUE the alpha blending mode will be used.

If the $enable = FALSE the alpha blending mode will not be used.

If $enable is not available when drawing on palette images.

This function returns on TRUECOLOR images the default value is TRUE.

This function returns by default FALSE on PALETTE images.

This function returns TRUE on success or FALSE on failure.





 IMAGE BLENDING 

refers to the process of creating a set of discrete samples of a continuous, one parameter family of images that connects a pair of input images.

Image blending has uses in a variety of computer graphics and image processing applications.

Blend modes, (or Mixing modes), in digital image editing and computer graphics are used to determine how two layers are blended into each other.

The default blend mode in most applications is simply to hide the lower layer with whatever is present in the top layer.

However, as each pixel has a numerical representation, a large number of ways to blend two layers is possible.

The top layer is not necessarily called a layer in the application.

It may be applied with a painting or editing tool.

The top layer can also be referred to as the blend layer or active layer.

( From Wikipedia, the free encyclopedia )



<?php

bool imagealphablending 
GdImage $imagebool $enable )

where,

$image The image identifier 

$enable 
To control if 
                         
the blend mode will be enable or not

?>

  $image   


The image identifier.



  $enable   


Whether to enable the blending mode or not.



  1 EXERCISE   

<?php

// RUN this code several times

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

$lang 'en';

$org_img "png/PNG 068 01.png";

$msk_img "png/PNG 068 01 mask.png";

$dst1_img "png/PNG 068 01 imagealphablending.png";

$en '<br><br>EXISTING IMAGE ';

$id_orgimg imagecreatefrompng($org_img);

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

<?php

$en 
'<br>IMAGE MASK ';

$id_mskimg imagecreatetruecolor (400265);
$bk_msk_color 
imagecolorallocate($id_mskimg255255255);

$rnred mt_rand(0255);
$rngreen mt_rand(0255);
$rnblue mt_rand(0255);

$alpha_color 
imagecolorallocatealpha($id_mskimg
                      
$rnred$rngreen$rnblue0);

$ndx_arr imagecolorsforindex($id_orgimg$alpha_color);

imagefill($id_mskimg00$bk_msk_color);
imagefilledrectangle($id_mskimg2000
                                                     
400265$alpha_color);

imagepng($id_mskimg$msk_img);

echo 
'<br><br>' $msk_img?><br> 
<?php echo $$lang?><br><br>
<?php print_r($ndx_arr); ?><br><br>
<img src="<?php echo $msk_img?>"
alt="<?php echo $msk_img?>
title="<?php echo $msk_img?>"><br><br>
<?php

$en 
'RESULTING IMAGE ';

$blend_mode1 mt_rand(01);

$org_bl_mode1 
imagealphablending($id_mskimg$blend_mode1); 

imagecopy($id_mskimg$id_orgimg0000400265);

imagepng($id_mskimg$dst1_img);

echo 
'<br>' $dst1_img?><br><br>
<?php echo $$lang?><br><br>
blendmode = <?php echo $blend_mode1?><br><br>
<img src="<?php echo $dst1_img?>"
alt="<?php echo $dst1_img?>
title="<?php echo $dst1_img?>">


 RESULT   

PNG 068 01.png

EXISTING IMAGE

PNG 068 01.png apr



PNG 068 01 mask.png

IMAGE MASK

Array
(
[red] => 172
[green] => 92
[blue] => 64
[alpha] => 0
)


PNG 068 01 masky.png apr


PNG 068 01 imagealphablending.png

RESULTING IMAGE

blendmode = 0


PNG 068 01 imagealphablendinn.png apr

RESULTING IMAGE

blendmode = 1


PNG 068 01 imagealphablendiny.png apr

This is a particular result.

For each new run a new result will be obtained.

So, try it yourself.


  2 EXERCISE   

<?php

// RUN this code several times

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

$lang 'en';

$org_img "png/PNG 069 02.png";

$msk_img "png/PNG 069 02 msky.png";

$dst2_img "png/PNG 069 02 imagealphablending.png";

$en '<br>EXISTING IMAGE ';

$id_orgimg 
imagecreatefrompng($org_img);

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

$id_mskimg 

imagecreatetruecolor (400265);
$bk_msk_color 
imagecolorallocate($id_mskimg255255255);

$rnred mt_rand(0255);
$rngreen mt_rand(0255);
$rnblue mt_rand(0255);

$alpha_color 
imagecolorallocatealpha($id_mskimg
                                        
$rnred
                                        
$rngreen
                                        
$rnblue0);

$ndx_arr 
imagecolorsforindex($id_orgimg$alpha_color);

imagefill($id_mskimg00$bk_msk_color);
imagefilledrectangle($id_mskimg00400265
                                                                
$alpha_color);

imagepng($id_mskimg$msk_img);

$en '<br>GENERATED MASK IMAGE';

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

echo '<pre>';
print_r($ndx_arr);
echo 
'</pre><br><br>';

$en '<br>RESULTING IMAGE ';

$blend_mode2 mt_rand(01); 

$org_bl_mode2 
imagealphablending($id_mskimg$blend_mode2); 

imagecopy($id_mskimg$id_orgimg0000400265);

imagepng($id_mskimg$dst2_img);

echo 
$dst2_img?><br><?php echo $$lang?><br>
blendmode = <?php echo $blend_mode2?>
<br><br><img src="<?php echo $dst2_img?>"
alt="<?php echo $dst2_img?>
title="<?php echo $dst2_img?>">


 RESULT   

PNG 069 02.png

EXISTING IMAGE

PNG 069 02.png apr

Run this exercise to see the result.

For each new run a new result will be obtained.