English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP imagealphablending() function usage and example

PHP Image Processing

imagealphablending — Set the blending mode of the image.

Syntax

bool imagealphablending ( resource $image , bool $blendmode )

imagealphablending() allows the use of two different painting modes on true color images.

In blending (blending) mode, the alpha channel color components are provided to all painting functions, such as imagesetpixel() determines the extent to which the underlying color should be allowed to shine through. As a result, GD automatically blends the existing color of the point and the brush color, and stores the result in the image. The resulting pixel is opaque.

In non-blending mode, the brush color along with its alpha channel information is copied and replaces the target pixel. Blending mode is not available when painting palette images.

If blendmode is TRUE, blending mode is enabled, otherwise disabled. Returns TRUE on success, or FALSE on failure.

Parameter

  • imageThe image resource returned by the image creation function (such as imagecreatetruecolor()).

  • blendmoderegardless of whether blending mode is enabled. True color images are default to True, otherwise FALSE.

Return value

Returns TRUE on success, or FALSE on failure.

Example

<?php
//  Create image
$im = imagecreatetruecolor(100, 100);
// Enable blending mode
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);
?>

PHP Image Processing