PHP | imagecolortransparent()函数

这个 imagecolortransparent() 函数是PHP中的一个内置函数,用于将颜色定义为透明。它设置透明图像的颜色。它返回新透明颜色的标识符。如果图像没有透明颜色,并且没有指定颜色,则返回-1。

null

语法:

int imagecolortransparent ( $image, $color )

参数: 该函数接受两个参数,如下所述:

  • $image: 它由一个图像创建函数返回,例如imagecreatetruecolor()。它用于创建图像的大小。
  • $color: 此参数用于设置imagecolorallocate()函数创建的颜色标识符。

返回值: 此函数返回新透明颜色的标识符。如果未指定图像的颜色,且图像没有透明颜色,则返回-1。

下面的程序说明了 imagecolortransparent() PHP中的函数:

项目1:

<?php
// Create an image of size 500x400
$image = imagecreatetruecolor(500, 400);
// Allocate green color to image
$green = imagecolorallocate( $image , 0, 153, 0);
// Allocate black color to image
$black = imagecolorallocate( $image , 0, 0, 0);
// Make the background transparent
imagecolortransparent( $image , $black );
// Draw a green filled rectangle
imagefilledrectangle( $image , 50, 50, 450, 300, $green );
// Output the image to the browser
header( 'Content-Type: image/png' );
imagepng( $image );
imagedestroy( $image );
?>


输出: image transparent

项目2:

<?php
// Create an image of size 500x400
$image = imagecreatetruecolor(500, 400);
// Allocate green color to image
$green = imagecolorallocate( $image , 0, 153, 0);
// Allocate black color to image
$black = imagecolorallocate( $image , 0, 0, 0);
// Make the background transparent
imagecolortransparent( $image , $black );
// Function to draw the circle
imageellipse( $image , 250, 200, 250, 250, $green );
// Output the image to the browser
header( 'Content-Type: image/png' );
imagepng( $image );
imagedestroy( $image );
?>


输出: transparent background image

相关文章:

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

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享