如何使用 PHP 中的 imageellipse() 函数绘制椭圆?
phpserver side programmingprogramming
imageellipse() 是 PHP 中的内置函数,用于绘制椭圆。成功时返回 True,失败时返回 False。
语法
Bool imageellipse($image, $cx, $cy, $width, $height, $color)
参数
imageellipse() 有六个不同的参数:$image、$cx、$cy、$width、$height、$color。
$image − 创建图像的大小。它由图像创建函数之一返回,例如 imagecreatetruecolor()。
$cx − 设置中心的 x 坐标。
$cy − 设置中心的 y 坐标。
$width − 设置椭圆的宽度。
$height − 设置椭圆的高度。
$color − 设置椭圆的颜色。由 imagecolorallocate() 函数创建的颜色标识符。
返回值
成功时返回 True,失败时返回 False。
示例 1
<?php // 创建一个空白图像。 $image = imagecreatetruecolor(700, 350); // 选择背景颜色。 $bg = imagecolorallocate($image, 0, 0, 0); // 用上面选择的颜色填充背景。 imagefill($image, 0, 0, $bg); // 为椭圆选择颜色。 $col_ellipse = imagecolorallocate($image, 255, 255, 255); // 绘制椭圆。 imageellipse($image, 325, 175, 500, 175, $col_ellipse); // 输出图像。 header("Content-type: image/png"); imagepng($image); ?>
输出
示例 2
<?php //它创建空白图像或图像的大小。 $image = imagecreatetruecolor(700, 600); //设置图像的背景颜色。 $bg = imagecolorallocate($image, 122, 122, 122); //用上面选择的颜色填充背景。 imagefill($image, 0, 0, $bg); // 设置椭圆的颜色。 $col_ellipse = imagecolorallocate($image, 0, 255, 255); // 绘制椭圆的函数。 imageellipse($image, 250, 300, 300, 550, $col_ellipse); // 输出图像。 header("Content-type: image/gif"); imagepng($image); ?>