PHP imagealphablending() Function: Setting Image Blending Mode
This article explains the PHP imagealphablending() function, its parameters, return values, and provides a complete example showing how to create a true‑color image, enable alpha blending, draw a shape, and output the result as a PNG.
The imagealphablending() function in PHP enables or disables alpha blending for true‑color images created with the GD library, allowing two different drawing modes.
Parameters
image : The image resource returned by functions such as imagecreatetruecolor().
blendmode : A boolean indicating whether to enable ( true) or disable ( false) blending mode.
Return value
Returns TRUE on success; on failure it returns FALSE.
Example usage
<?php
// Create image
$im = imagecreatetruecolor(100, 100);
// Set alphablending to on
imagealphablending($im, true);
// Draw a square
imagefilledrectangle($im, 30, 30, 70, 70, imagecolorallocate($im, 255, 0, 0));
// Output
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>This example demonstrates creating a 100×100 image, enabling alpha blending, drawing a red square, and sending the image to the browser as a PNG.
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.
