imagerectangle()函數是PHP中的一個內置函數,用於繪製矩形。
用法:
bool imagerectangle( $image, $x1, $y1, $x2, $y2, $color )
參數:該函數接受上述和以下所述的六個參數:
- $image:它由圖像創建函數之一(例如imagecreatetruecolor())返回。它用於創建圖像的尺寸。
- $x1:此參數用於設置左上角的x坐標。
- $y1:此參數用於設置左上方的y坐標。
- $x2:此參數用於設置右下角的x坐標。
- $y2:此參數用於設置右下角的y坐標。
- $color:使用imagecolorallocate()創建的顏色標識符。
返回值:如果成功,此函數返回True;如果失敗,則返回False。
以下示例程序旨在說明PHP中的imagerectangle()函數:
示例1:
<?php
// Create an image of given size
$image = imagecreatetruecolor(400, 400);
// Create an image color
$green = imagecolorallocate($image, 0, 153, 0);
$white = imagecolorallocate($image, 255, 255, 255);
// Draw the rectangle
imagerectangle($image, 50, 50, 350, 350, $green);
imagerectangle($image, 100, 100, 300, 300, $white);
// Output and free from memory
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
?>
輸出:
示例2:
<?php
// Create an image of given size
$image = imagecreatetruecolor(400, 400);
// 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);
// Create an image color
$green = imagecolorallocate($image, 0, 153, 0);
$white = imagecolorallocate($image, 155, 53, 32);
// Draw the rectangle
imagerectangle($image, 50, 50, 350, 350, $green);
imagerectangle($image, 100, 100, 300, 300, $white);
// Output and free from memory
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
?>
輸出:
參考: http://php.net/manual/en/function.imagerectangle.php
相關用法
- p5.js pow()用法及代碼示例
- p5.js day()用法及代碼示例
- PHP each()用法及代碼示例
- d3.js d3.min()用法及代碼示例
- PHP tan( )用法及代碼示例
- p5.js cos()用法及代碼示例
- PHP pos()用法及代碼示例
- p5.js sin()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP key()用法及代碼示例
- p5.js log()用法及代碼示例
- p5.js sq()用法及代碼示例
注:本文由純淨天空篩選整理自Mahadev99大神的英文原創作品 PHP | imagerectangle() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。