PHP imageline() function

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 //from  w  ww.  j  a va2s.c om
  $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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions