PHP imagelayereffect Function: Setting Alpha Blending for GD Layered Effects
The PHP GD library function imagelayereffect sets an alpha blending flag to enable layered effects such as overlay on an image resource, describing its parameters, return values, and providing a complete example that creates, modifies, outputs, and destroys an image.
The imagelayereffect function in PHP's GD library enables the setting of an alpha blending flag to apply layered effects such as overlay on an image resource.
Parameters : $image – a GD image resource created by functions like imagecreatetruecolor(); $effect – an integer constant specifying the effect (e.g., IMG_EFFECT_OVERLAY).
Return value : on success it returns the image resource; on failure it returns FALSE.
Example usage demonstrates creating a 100×100 image, filling a background, applying the overlay effect, drawing grey ellipses, sending the PNG header, outputting the image with imagepng, and freeing resources with imagedestroy:
<?php
// Setup an image
$im = imagecreatetruecolor(100,100);
// Set a background
imagefilledrectangle($im,0,0,100,100,imagecolorallocate($im,220,220,220));
// Apply the overlay alpha blending flag
imagelayereffect($im,IMG_EFFECT_OVERLAY);
// Draw two grey ellipses
imagefilledellipse($im,50,50,40,40,imagecolorallocate($im,100,255,100));
imagefilledellipse($im,50,50,80,80,imagecolorallocate($im,100,255,100));
imagefilledellipse($im,50,50,80,80,imagecolorallocate($im,255,100,100));
// Output
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
