PHP | imagefilledrectangle()函数

这个 imagefilledrectangle() 函数是PHP中的一个内置函数,用于创建填充矩形。此函数用于在图像中创建一个填充给定颜色的矩形。图像的左上角是(0,0)。

null

语法:

bool imagefilledrectangle( $image, $x1, $y1, $x2, $y2, $color )

参数: 此函数接受六个参数,如下所述:

  • $image: 它由一个图像创建函数返回,例如imagecreatetruecolor()。它用于创建图像的大小。
  • x1美元: 此参数用于设置点1的x坐标。
  • y1美元: 此参数用于设置点1的y坐标。
  • $x2: 此参数用于设置点2的x坐标。
  • y2美元: 此参数用于设置点2的y坐标。
  • $color: 此参数包含填充的颜色标识符。使用imagecolorallocate()函数创建的颜色标识符。

返回值: 此函数在成功时返回True,失败时返回False。

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

项目1:

<?php
// Create an image of given size
$image = imagecreatetruecolor(500, 300);
$green = imagecolorallocate( $image , 0, 153, 0);
// Draw the rectangle of green color
imagefilledrectangle( $image , 20, 20, 480, 280, $green );
// Output image in png format
header( "Content-type: image/png" );
imagepng( $image );
// Free memory
imagedestroy( $image );
?>


输出: imagerectanglefilled

项目2:

<?php
// Create an image of given size
$image = imagecreatetruecolor(500, 300);
$white = imagecolorallocate( $image , 255, 255, 255);
// Draw the rectangle of white color
imagefilledrectangle( $image , 20, 20, 480, 280, $white );
// Output image
header( "Content-type: image/png" );
imagepng( $image );
// Free memory
imagedestroy( $image );
?>


输出: imagerectanglefilled

相关文章:

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

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