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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP imagelayereffect Function: Setting Alpha Blending for GD Layered Effects

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);
?>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Overlayalpha-blendingimage-processingimagelayereffect
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.