Sunday, November 17, 2024
Google search engine
HomeLanguagesPHP | imagedashedline() Function

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:
dotted image

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:
dotted image

Related Articles:

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

RELATED ARTICLES

Most Popular

Recent Comments