PHP | imagedashedline() Function
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 // 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); ?> |
Output:

Program 2:
<?php // 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); ?> |
Output:

Related Articles:
- PHP | imagefilledpolygon() Function
- PHP | imageellipse() Function
- PHP | imagefilledellipse() Function
Reference: http://php.net/manual/en/function.imagedashedline.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- PHP | Ds\Set contains() Function
- PHP | cos( ) Function
- PHP | end() Function
- PHP | pos() Function
- PHP | Ds\Map put() Function
- PHP | key() Function
- p5.js | value() Function
- PHP | Ds\Map xor() Function
- PHP | tan( ) Function
- p5.js | max() function
- p5.js | pow() function
- p5.js | day() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

