PHP imagealphablending()函数用法介绍

2021年3月17日17:16:25 发表评论 681 次浏览

imagealphablending()function是PHP中的内置函数, 用于设置图像的混合模式。此功能允许使用两种不同的模式(混合模式和非混合模式)来绘制真彩色图像。绘制使用的调色板图像时, 混合模式不可用。

语法如下:

bool imagealphablending( $image, $blendmode )

参数:此函数接受上述和以下所述的两个参数:

  • $ image:它由图像创建功能之一(例如imagecreatetruecolor())返回。它用于创建图像尺寸。
  • $ blendmode:此参数用于检查混合模式是否启用。对于真彩色图像, 默认值为True;否则为False。

返回值:如果成功, 此函数返回True;如果失败, 则返回False。

下面的程序说明了imagealphablending()PHP中的功能:

程序1:

<?php
  
// Create an image of given size
$image = imagecreatetruecolor(300, 500);
  
// Set alphablending to on
imagealphablending( $image , true);
  
// Set the background color of image. 
$background_color = imagecolorallocate( $image , 255, 255, 255); 
     
// Fill background with above selected color. 
imagefill( $image , 0, 0, $background_color ); 
  
// Draw a square of given size
imagefilledrectangle( $image , 50, 50, 450, 250, imagecolorallocate( $image , 0, 255, 0));
  
// Output image
header( 'Content-Type: image/png' );
  
imagepng( $image );
imagedestroy( $image );
?>

输出如下:

PHP | imagealphablending()函数1

程式2:

<?php
  
// Create an image from png
$image = imagecreatefrompng( 
'https://media.lsbin.org/wp-content/uploads/lsbin-9.png' ); 
  
// Set alphablending to image
imagealphablending( $image , true);
  
// Create color of image
$green = imagecolorallocate( $image , 0, 255, 0); 
     
// Create rectangle
imagerectangle( $image , 5, 10, 660, 100, $green );
  
// Output image
header( 'Content-Type: image/png' );
  
imagepng( $image );
imagedestroy( $image );
?>

输出如下:

PHP | imagealphablending()函数2

参考: http://php.net/manual/en/function.imagealphablending.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: