imagefilledrectangle()函數是PHP中的一個內置函數,用於創建填充矩形。此函數在圖像中創建一個填充有給定顏色的矩形。圖像的左上角是(0,0)。
用法:
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。
以下示例程序旨在說明PHP中的imagefilledrectangle()函數:
程序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);
?>
輸出:
程序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);
?>
輸出:
相關文章:
參考: http://php.net/manual/en/function.imagefilledrectangle.php
相關用法
- PHP each()用法及代碼示例
- CSS var()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP end()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- p5.js int()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP cos( )用法及代碼示例
- PHP key()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP pos()用法及代碼示例
- PHP abs()用法及代碼示例
注:本文由純淨天空篩選整理自Mahadev99大神的英文原創作品 PHP | imagefilledrectangle() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。