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:
- $image: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image.
- $effect: This parameter set the value of effect constant. The value of effect constants are listed below:
- IMG_EFFECT_REPLACE: It is used to set the pixel replacement. It is equivalent to passing True to imagealphablending() function.
- IMG_EFFECT_ALPHABLEND: It is used to set the normal pixel blending. It is equivalent to passing False to imagealphablending() function.
- IMG_EFFECT_NORMAL: It is same as IMG_EFFECT_ALPHABLEND.
- IMG_EFFECT_OVERLAY: It is the effect where black background pixels will remain black, white background pixels will remain white but grey background pixels will take the color the foreground pixel.
- IMG_EFFECT_MULTIPLY: It sets the multiply effect.
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