imagedashedline()函数是PHP中的内置函数,用于绘制虚线。成功时此函数返回TRUE,否则返回FALSE。
用法:
bool imagedashedline( $image , $x1 , $y1 , $x2 , $y2 , $color )
参数:该函数接受上述和以下所述的六个参数:
$image:imagecreatetruecolor()函数用于创建给定尺寸的空白图像。
$x1:此参数用于保留左上角的x坐标。
$y1:此参数用于保留左上y坐标。 (0,0)是图像的左上角。
$x2:此参数用于保存右下角的x坐标。
$y2:此参数用于保留右下角的y坐标。
$color:此变量包含填充的颜色标识符。使用imagecolorallocate()函数创建的颜色标识符。
返回值:如果成功,则此函数返回TRUE;如果失败,则返回FALSE。
以下示例程序旨在说明PHP中的imagedashedline()函数。
程序1:
// Create the size of image or blank image
$image = imagecreatetruecolor(400, 300);
// Set the background color of image
$background_color = imagecolorallocate($image, 0, 153, 0);
// Fill background with above selected color
imagefill($image, 0, 0, $background_color);
// Set the color of dotted line in image
$color = imagecolorallocate($image, 255, 255, 255);
// Draw a dashed line
imagedashedline($image, 0, 0, 100, 150, $color);
// Output the image
header("Content-type: image/png");
imagepng($image);
?>
输出:
程序2:
// Create the size of image or blank image
$image = imagecreatetruecolor(400, 300);
// Set the background color of image
$background_color = imagecolorallocate($image, 0, 153, 0);
// Fill background with above selected color
imagefill($image, 0, 0, $background_color);
// Set the color of dotted line in image
$white = imagecolorallocate($image, 255, 255, 255);
// $value is an array variable stored color
// code of dotted image
$values = Array(
$white,
$white,
$white,
$white,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT
);
imagesetstyle($image, $values);
// Draw the dashed line
imageline($image, 50, 150, 300, 150, IMG_COLOR_STYLED);
// Save the image
header("Content-type: image/png");
imagepng($image);
?>
输出:
相关文章: