imagelayereffect 


gd apg

SET the alpha blending flag to use layering effects.





Since PHP 7.2.0 was added IMG_EFFECT_MULTIPLY that requires system libgd greater than or equal to 2.1.1 or the bundled libgd.

This function returns TRUE on success or FALSE on failure.



<?php

bool imagelayereffect 
GdImage $imageint $effect )

where,

$image The image identifier

$effect 
The effect to be used
              
SEE the below TABLE )

?> 

  $image   


The image identifier.



  $efect   


The efect mode. One of the constants:

IMAGE LAYER EFFECT CONSTANTS
CONSTANT VALUE MEANING
IMG_EFFECT_REPLACE 0 Use pixel replacement.
Equivalent of passing TRUE to imagealphablending.
IMG_EFFECT_ALPHABLEND 1 Use pixel replacement.
Equivalent of passing FALSE to imagealphablending.
IMG_EFFECT_NORMAL 2 Same as IMG_EFFECT_ALPHABLEND.
IMG_EFFECT_OVERLAY 3 Overlay has the effect that black background pixels will remain black, white background pixels will remain white, but grey background pixels will take the colour of the foreground pixel.
IMG_EFFECT_MULTIPLY 4 Overlays with a multiply effect.
ed48


  1 EXERCISE   

<?php

// RUN this code several times

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

$lang 'en';

$org_img "jpeg/JPEG 031 01.jpg";

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

$dst_img "png/PNG 070 01 imagelayereffect.png";

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

$id_orgimg imagecreatefromjpeg($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><br>

<?php

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

$id_mskimg imagecreatetruecolor (400400);

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

$alphfac mt_rand(0127);

$alpha_color imagecolorallocatealpha($id_mskimg
                                                                 
$rnred
                                                                 
$rngreen
                                                                 
$rnblue
                                                                 
$alphfac);

imagefill($id_mskimg00$alpha_color);

imagepng($id_mskimg$msk_img);


echo 
$msk_img?><?php echo $$lang?><br>
<?php echo 'RGB = ( ' $rnred ', ' $rngreen ', ' 
$rnblue ' )<br><br>'?>
<img src="<?php echo $msk_img?>"
alt="<?php echo $msk_img?>
title="<?php echo $msk_img?>"><br><br>
<?php

$effect01 
= [ IMG_EFFECT_REPLACEIMG_EFFECT_ALPHABLEND
                    
IMG_EFFECT_NORMALIMG_EFFECT_OVERLAY
                    
IMG_EFFECT_MULTIPLY ];

$effect02 = [ "IMG_EFFECT_REPLACE""IMG_EFFECT_ALPHABLEND"
                    
"IMG_EFFECT_NORMAL""IMG_EFFECT_OVERLAY"
                    
"IMG_EFFECT_MULTIPLY" ];

$eff01 mt_rand(04);  

$effname $effect02[$eff01];

imagelayereffect($id_mskimg$eff01);

imagecopy($id_orgimg$id_mskimg200000400400);
imagepng($id_orgimg$dst_img);
$md2_type $effname '<br>ALPHA = ' $alphfac;

echo 
$dst_img .'<br><br>' $md2_type?><br><br>
<img src="<?php echo $dst_img?>"
alt="<?php echo $dst_img?>
title="<?php echo $dst_img?>"><br>


 RESULT   

JPEG 031 01.jpg

EXISTING IMAGE

JPEG 031 01.jpg apr


PNG 070 01 mask.png

MASK IMAGE
RGB = ( 90, 135, 29 )


PNG 070 01 mask.png apr

PNG 070 01 imagelayereffect.png

IMG_EFFECT_OVERLAY
ALPHA = 39


PNG 070 01 imagelayereffect.png apr

This is a particular result.

With each new run a new result will be obtained.

So, try yourself


  2 EXERCISE   

<?php

// RUN this code several times

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

$lang 'en';

$org_img "jpeg/JPEG 031 01.jpg";

$msk_img "png/PNG 070 02 mask.png";

$dst_img "png/PNG 070 02 imagelayereffect.png";

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

$id_orgimg imagecreatefromjpeg($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><br>

<?php

$en 
'<br>MASK IMAGE';

$id_mskimg imagecreatetruecolor (400400);

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

$alphfac mt_rand(0127);

$alpha_color imagecolorallocatealpha($id_mskimg
                                                                
$rnred
                                                                
$rngreen
                                                                
$rnblue
                                                                
$alphfac);

imagefill($id_mskimg00$alpha_color);

imagepng($id_mskimg$msk_img);


echo 
$msk_img?><?php echo $$lang?><br>
<?php echo 'RGB = ( ' $rnred ', ' $rngreen ', ' 
                                                
$rnblue ' )<br><br>'?>
<img src="<?php echo $msk_img?>"
alt="<?php echo $msk_img?>
title="<?php echo $msk_img?>"><br><br>
<?php

$effect01 
= [ IMG_EFFECT_REPLACEIMG_EFFECT_ALPHABLEND
                    
IMG_EFFECT_NORMALIMG_EFFECT_OVERLAY
                    
IMG_EFFECT_MULTIPLY ];

$effect02 = [ "IMG_EFFECT_REPLACE""IMG_EFFECT_ALPHABLEND"
                   
"IMG_EFFECT_NORMAL""IMG_EFFECT_OVERLAY"
                   
"IMG_EFFECT_MULTIPLY" ];

$eff01 mt_rand(04);  

$effname $effect02[$eff01];

imagelayereffect($id_mskimg$eff01);

imagecopy($id_orgimg$id_mskimg0000400400);
imagepng($id_orgimg$dst_img);
$md2_type '<br>' $effname '<br>ALPHA = ' $alphfac;

echo 
$dst_img?> <?php echo $md2_type?><br><br>
<img src="<?php echo $dst_img?>"
alt="<?php echo $dst_img?>
title="<?php echo $dst_img?>"><br><br>


 RESULT   

JPEG 031 01.jpg

EXISTING IMAGE

JPEG 031 01.jpg apr


PNG 070 02 mask.png

MASK IMAGE
RGB = ( 148, 78, 209 )


PNG 070 02 mask.png apr

PNG 070 02 imagelayereffect.png

IMG_EFFECT_NORMAL
ALPHA = 99


PNG 070 02 imagelayereffect.png  apr

This is a particular result.

With each new run a new result will be obtained.

So, try yourself