Open In App

PHP | imagelayereffect() Function

The imagelayereffect() function is an inbuilt function in PHP which is used to set the alpha blending flag to use layering effects. This function returns True on success or False on failure.

Syntax:



bool imagelayereffect( $image, $effect )

Parameters: This function accepts two parameters as mentioned above and described below:

Return Value: This function returns True on success or False on failure.



Below programs illustrate the imagelayereffect() function in PHP:

Program 1:




<?php
// Setup an image
$im = imagecreatetruecolor(200, 200);
  
// Set a background
imagefilledrectangle($im, 0, 0, 200, 200, imagecolorallocate($im, 220, 220, 220));
  
// Apply the overlay alpha blending flag
imagelayereffect($im, IMG_EFFECT_OVERLAY);
  
// Draw two grey ellipses
imagefilledellipse($im, 100, 100, 160, 160, imagecolorallocate($im, 100, 255, 100));
imagefilledellipse($im, 100, 100, 140, 140, imagecolorallocate($im, 100, 100, 255));
imagefilledellipse($im, 100, 100, 100, 100, imagecolorallocate($im, 255, 100, 100));
  
// Output
header('Content-type: image/png');
  
imagepng($im);
imagedestroy($im);
?>

Output:

Program 2:




<?php
// Setup an image
$im = imagecreatetruecolor(200, 200);
  
// Set a background
imagefilledrectangle($im, 0, 0, 200, 200, imagecolorallocate($im, 220, 220, 220));
  
// Apply the overlay alpha blending flag
imagelayereffect($im, IMG_EFFECT_REPLACE);
  
// Draw two grey ellipses
imagefilledellipse($im, 100, 100, 160, 160, imagecolorallocate($im, 100, 255, 100));
imagefilledellipse($im, 100, 100, 140, 140, imagecolorallocate($im, 100, 100, 255));
imagefilledellipse($im, 100, 100, 100, 100, imagecolorallocate($im, 255, 100, 100));
  
// Output
header('Content-type: image/png');
  
imagepng($im);
imagedestroy($im);
?>

Output:

Reference: http://php.net/manual/en/function.imagelayereffect.php


Article Tags :