PHP | imageline() Function
Last Updated :
31 Jan, 2020
The imageline() function is an inbuilt function in PHP which is used to set the draws a line between the two given points.
Syntax:
bool imageline( resource $image, int $x1, int $y1,
int $x2, int $y2, int $color )
Parameters: This function accepts six parameters as mentioned above and described below:
- $image: It specifies the image resource to work on.
- $x1: It specifies the starting x-coordinate.
- $y1: It specifies the starting y-coordinate.
- $x2: It specifies the ending x-coordinate.
- $y2: It specifies the ending y-coordinate.
- $color: It specifies the line color.
Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the imageline() function in PHP:
Example 1: In this example add a line to a image.
<?php
$im = imagecreatefrompng(
$text_color = imagecolorallocate( $im , 255, 0, 0);
imageline( $im , 40, 100, 640, 100, $text_color );
header( 'Content-type: image/png' );
imagepng( $im );
imagedestroy( $im );
?>
|
Output:
Example 2: In this example we will add a line to a drawing.
<?php
$im = imagecreate(700, 200);
$yellow = imagecolorallocate( $im , 255, 255, 0);
$blue = imagecolorallocate( $im , 0, 0, 255);
imageline( $im , 0, 0, 700, 200, $yellow );
imageline( $im , 0, 0, 840, 250, $blue );
header( 'Content-type: image/png' );
imagepng( $im );
imagedestroy( $im );
?>
|
Output:
Reference: https://www.php.net/manual/en/function.imageline.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...