imagealphablending

Set the blending mode for an image

Description

bool imagealphablending(GdImage $image, bool $enable)

imagealphablending allows for two different modes of drawing on truecolor images. In blending mode, the alpha channel component of the color supplied to all drawing function, such as imagesetpixel determines how much of the underlying color should be allowed to shine through. As a result, gd automatically blends the existing color at that point with the drawing color, and stores the result in the image. The resulting pixel is opaque. In non-blending mode, the drawing color is copied literally with its alpha channel information, replacing the destination pixel. Blending mode is not available when drawing on palette images.

Parameters

image

A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor.

enable

Whether to enable the blending mode or not. On true color images the default value is true otherwise the default value is false

Return Values

Returns true on success or false on failure.

Changelog

Version Description
8.0.0 image expects a GdImage instance now; previously, a valid gd resource was expected.

Examples

Example #1 imagealphablending usage example

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