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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
   
?>

chevron_right


Output:
dotted image

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?>

chevron_right


Output:
dotted image

Related Articles:

Reference: http://php.net/manual/en/function.imagedashedline.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.