imageline 


gd apg

DRAW a line in an image.





$x = 0 and $y = 0 are the coordinates of the top left point.

This function returns TRUE on success or FALSE on failure.



<?php

bool imageline 
GdImage $image
                                    
int $x1 int $y1 
                                    
int $x2 int $y2 
                                                 
int $color )


where,

$image The image identifier 

$x1 
The x-coordinate of the start point 

$y1 
The y-coordinate of the start point 

$x2 
The x-coordinate of the end point 

$y2 
The y-coordinate of the end point 

$color 
The fill color as returned by imagecolorallocate

?>
 

  $image   


The image identifier.



  $x1   


x-coordinate of start point.



  $y1   


y-coordinate of start point.



  $x2   


x-coordinate of end point.



  $y2   


y-coordinate of end point.



  $color   


The fill color, a color identifier created by imagecolorallocate.



  1 EXERCISE   

<?php

$lang 
'en';

$sup_img 'png/baseXx.png';

$res1_img ='png/PNG 053 01 baseXx imageline.png';

$id_sup_img imagecreatefrompng($sup_img);

$en 'Existing Image';
 echo 
basename($sup_img) . '<br><br>' . $$lang?>
<br><br><img src="<?php echo  
$sup_img?>" alt="<?php echo $sup_img?>"><br><br>

<?php

$x10 
30;
$y10 30;
$x1N 340;
$y1N 250;

$ln1_red 0;
$ln1_green 0;
$ln1_blue 255;
$ln1_color imagecolorallocate($id_sup_img
                                     
$ln1_red$ln1_green$ln1_blue);

$x20 340;
$y20 50;
$x2N 100;
$y2N 250;

$ln2_red 255;
$ln2_green 0;
$ln2_blue 0;
$ln2_color imagecolorallocate($id_sup_img
                                       
$ln2_red$ln2_green$ln2_blue);

$ln1 imageline($id_sup_img$x10$y10
                                       
$x1N$y1N$ln1_color);


$ln2 imageline($id_sup_img$x20$y20
                                     
$x2N$y2N$ln2_color);

imagepng($id_sup_img,  $res1_img);

$ln1 imageline($id_sup_img$x10$y10
                                     
$x1N$y1N$ln1_color);
                                     
$ln2 imageline($id_sup_img$x20
                                     
$y20$x2N$y2N$ln2_color);

?>
<br>
<?php echo basename($res1_img); ?><br><br>
<img src="<?php echo  $res1_img?>
alt="<?php echo $res1_img?>"><br><br>

<?php imagedestroy($id_sup_img); ?> 


 RESULT   

baseXx.png

Existing image

baseXx.png apr

PNG 053 01 baseXx imageline.png

Resulting image

PNG 053 01 baseXx imageline.png apr