PHP imagealphablending - Set image blending mode

PHP 图像处理PHP Image Processing

imagealphablending — Set the blending mode for an image.

Syntax

bool imagealphablending ( resource $image , bool $blendmode )

imagealphablending() allows two different painting modes to be used on true-color images.

In blending mode, the alpha channel color component is provided to all drawing functions, such as imagesetpixel(), to determine the extent to which the underlying color is allowed to show through. As a result, GD automatically blends the existing color at that point with the brush color and stores the result in the image. The resulting pixel is opaque.

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

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

Parameters

  • imageAn image resource returned by an image creation function (e.g., imagecreatetruecolor()).
  • blendmodeWhether to enable blending mode. Defaults to TRUE for true-color images, otherwise FALSE.

Return Value

Returns TRUE on success or FALSE on failure.

Examples

<?php
//  创建图像
$im = imagecreatetruecolor(100, 100);

// 启用混色模式
imagealphablending($im, true);

// 画一个正方形
imagefilledrectangle($im, 30, 30, 70, 70, imagecolorallocate($im, 255, 0, 0));

// 输出
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

PHP 图像处理PHP Image Processing

Other Extensions