PHP | imagedashedline() Function
Last Updated :
23 Aug, 2019
The imagedashedline() function is an inbuilt function in PHP which is used to draw a dashed line. This function returns TRUE on success and returns FALSE otherwise.
Syntax:
bool imagedashedline( $image , $x1 , $y1 , $x2 , $y2 , $color )
Parameters: This function accepts six parameters as mentioned above and described below:
- $image: The imagecreatetruecolor() function is used to create a blank image in a given size.
- $x1: This parameter is used to hold the top left x coordinate.
- $y1: This parameter is used to hold the top left y coordinate. (0, 0) is the top left corner of the image.
- $x2: This parameter is used to hold the bottom right x coordinate.
- $y2: This parameter is used to hold the bottom right y coordinate.
- $color: This variable contains the filled color identifier. A color identifier created with imagecolorallocate() function.
Return Value: This function returns TRUE on success or FALSE on failure.
Below programs illustrate the imagedashedline() function in PHP.
Program 1:
<?php
$image = imagecreatetruecolor(400, 300);
$background_color = imagecolorallocate( $image , 0, 153, 0);
imagefill( $image , 0, 0, $background_color );
$color = imagecolorallocate( $image , 255, 255, 255);
imagedashedline( $image , 0, 0, 100, 150, $color );
header( "Content-type: image/png" );
imagepng( $image );
?>
|
Output:
Program 2:
<?php
$image = imagecreatetruecolor(400, 300);
$background_color = imagecolorallocate( $image , 0, 153, 0);
imagefill( $image , 0, 0, $background_color );
$white = imagecolorallocate( $image , 255, 255, 255);
$values = Array(
$white ,
$white ,
$white ,
$white ,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT
);
imagesetstyle( $image , $values );
imageline( $image , 50, 150, 300, 150, IMG_COLOR_STYLED);
header( "Content-type: image/png" );
imagepng( $image );
?>
|
Output:
Related Articles:
Reference: http://php.net/manual/en/function.imagedashedline.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...