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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP imagealphablending() Function: Setting Image Blending Mode

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.

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.

Image ProcessingPHPimagealphablending
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.