PHP如何使用imagearc()函数创建圆弧?代码示例

2021年4月3日18:58:04 发表评论 915 次浏览

imagearc()函数PHP中的内置函数, 用于创建以给定坐标为中心的圆弧。成功时此函数返回true, 失败时返回false。

语法如下:

bool imagearc( $image, $cx, $cy, $width, $height, $start, $end, $color )

参数:该函数接受上述和以下所述的八个参数:

  • $image:它由图像创建功能之一(例如imagecreatetruecolor())返回。它用于创建图像尺寸。
  • $cx:用于设置中心的x坐标。
  • $cy:用于设置中心的y坐标。
  • $width:弧的宽度。
  • $height:弧的高度。
  • $start:它用于设置弧起始角度(以度为单位)。
  • $end:它用于设置圆弧末端角度(以度为单位)。 0度位于三点钟的位置, 并且弧线是顺时针绘制的。
  • $color:它设置图像的颜色。由imagecolorallocate()函数创建的颜色标识符。

返回值:成功时此函数返回true, 失败时返回false。

下面的程序说明了imagearc()PHP中的功能。

程序1:

<?php
  
// It create the size of image or blank image.
$image_size = imagecreatetruecolor(500, 300);
  
// Set the background color of image.
$bg = imagecolorallocate( $image_size , 0, 103, 0);
  
// Fill background with above selected color.
imagefill( $image_size , 0, 0, $bg ); 
  
// Set the colors of image
$white_color = imagecolorallocate( $image_size , 255, 255, 255);
$red_color = imagecolorallocate( $image_size , 255, 0, 0);
$green_color = imagecolorallocate( $image_size , 0, 255, 0);
$blue_color = imagecolorallocate( $image_size , 0, 0, 255);
  
// Draw the circle
imagearc( $image_size , 200, 150, 200, 200, 0, 360, $white_color );
imagearc( $image_size , 200, 150, 150, 150, 25, 155, $red_color );
imagearc( $image_size , 260, 110, 50, 50, 0, 360, $green_color );
imagearc( $image_size , 140, 110, 50, 50, 0, 360, $blue_color );
  
// Output image in the browser
header( "Content-type: image/png" );
imagepng( $image_size );
  
// Free memory
imagedestroy( $image_size );
  
?>

输出如下:

PHP如何使用imagearc()函数创建圆弧?代码示例

程序2:

<?php
  
// It create the size of image or blank image.
$image_size = imagecreatetruecolor(500, 300);
  
// Set the background color of image.
$bg = imagecolorallocate( $image_size , 0, 102, 0);
  
// Fill background with above selected color.
imagefill( $image_size , 0, 0, $bg ); 
  
// Set the colors of image
$white_color = imagecolorallocate( $image_size , 255, 255, 255);
$red_color = imagecolorallocate( $image_size , 255, 0, 0);
$black_color = imagecolorallocate( $image_size , 0, 0, 0);
  
// Draw the arc circle image
imagearc( $image_size , 200, 150, 200, 200, 0, 360, $white_color );
imagearc( $image_size , 200, 150, 150, 150, 0, 360, $red_color );
imagearc( $image_size , 200, 150, 50, 50, 0, 360, $black_color );
  
// Output image in the browser
header( "Content-type: image/png" );
imagepng( $image_size );
  
// Free memory
imagedestroy( $image_size );
  
?>

输出如下:

PHP如何使用imagearc()函数创建圆弧?代码示例

相关文章:

  • PHP | imagepolygon()函数
  • PHP | imagefilledellipse()函数
  • PHP | imagefilledpolygon()函数

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


木子山

发表评论

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