PHP imageline() function
In this chapter you will learn:
- What is PHP imageline() function
- Syntax for PHP imageline() function
- Parameter for PHP imageline() function
- Return value for PHP imageline() function
- Example -
- Note for imagecreate() error
Description
Draws a line between the two given points.
Syntax
PHP imageline() function has the following syntax.
bool imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )
Parameter
PHP imageline() function has the following parameters.
- image - An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
- x1 - x-coordinate for first point.
- y1 - y-coordinate for first point.
- x2 - x-coordinate for second point.
- y2 - y-coordinate for second point.
- color - The line color. A color identifier created with imagecolorallocate().
Return
Returns TRUE on success or FALSE on failure.
Example
In this simple example you draw a straight line between two points, then output the resulting image to the browser.
<?php /* j a va 2 s. c o m*/
$myImage = imagecreate( 200, 100 );
$myGray = imagecolorallocate( $myImage, 204, 204, 204 );
$myBlack = imagecolorallocate( $myImage, 0, 0, 0 );
imageline( $myImage, 15, 35, 120, 60, $myBlack );
header( "Content-type: image/png" );
imagepng( $myImage );
imagedestroy( $myImage );
?>
Note
If you receive an undefined function imagecreate() error message on Windows, enable the GD2 extension.
Edit your php.ini file and remove the semicolon from the start of the following line:
;extension=php_gd2.dll
Restart your server after you've made this change.
Next chapter...
What you will learn in the next chapter:
- What is PHP imagepolygon() function
- Syntax for PHP imagepolygon() function
- Parameter for PHP imagepolygon() function
- Point Format
- Return value for PHP imagepolygon() function
- Example - PHP imagepolygon() function
Home » PHP Tutorial » PHP Image Functions