Contents
Login Register Wishes Forum About
Language Reference » Drawing functions » drawLine
Help topics
Latest updates
2145d  replaceImageMapTitle
2145d  replaceImageMapValues
2145d  createFunctionSerie
2145d  setAbsicssaPosition
2145d  negateValues
Toolbox
  Download as PDF
  Print this page
  Share this page
  Create an account
  Feed the updates!
Google AdSense
drawLine - Drawing lines

This function allows you to draw aliased lines on your pictures. It is possible to tune the rendering by playing with the $Format array. To learn more about this please read the Format array guide. Lines like all simple drawing functions are supporting anti-alias and shadows.

This function is also used internally by a lot of drawing functions.

Calling this function
drawLine($X1,$Y1,$X2,$Y2,$Format="");
Where :

X1,Y1 are the start coordinate of the line.
X2,Y2 are the end coordinate of the line.
Format is an array containing the drawing parameters of the arrow.


Customisation array - Tune up your line!

It is possible to customize the line rendering by playing with this array. Providing a detailled configuration is not mandatory, by default the line will be drawn black with no transparency.

The line color can be set with R, G, B.
The alpha transparency factor can be set with Alpha.
You can draw dashed lines using the Ticks parameter.
You can specify the weight of the line with the Weight parameter.


Sample script



 /* Enable shadow support */
 /* pChart library inclusions */
 include("../class/pDraw.class.php");
 include("../class/pImage.class.php");

 /* Create the pChart object */
 $myPicture = new pImage(700,230);

 /* Draw the background */
 $Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
 $myPicture->drawFilledRectangle(0,0,700,230,$Settings);

 /* Overlay with a gradient */
 $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
 $myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);
 $myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));

 /* Draw the picture border */ 
 $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
 
 /* Write the picture title */ 
 $myPicture->setFontProperties(array("FontName"=>"../fonts/Silkscreen.ttf","FontSize"=>6));
 $myPicture->drawText(10,13,"drawLine() - Basis",array("R"=>255,"G"=>255,"B"=>255));

 /* Turn on shadow computing */ 
 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));

 /* Draw some lines */ 
 for($i=1;$i<=100;$i=$i+4)
  $myPicture->drawLine($i+5,215,$i*7+5,30,array("R"=>rand(0,255),"G"=>rand(0,255),"B"=>rand(0,255),"Ticks"=>rand(0,4)));

 /* Draw an horizontal dashed line with extra weight */
 $myPicture->drawLine(370,160,650,160,array("R"=>0,"G"=>0,"B"=>0,"Ticks"=>4,"Weight"=>3));

 /* Another example of extra weight */
 $myPicture->drawLine(370,180,650,200,array("R"=>255,"G"=>255,"B"=>255,"Ticks"=>15,"Weight"=>1));

 /* Render the picture (choose the best way) */
 $myPicture->autoOutput("pictures/example.drawLine.png");

This will draw 25 lines with random colors. As the shadow support is enabled on line 2, the line will be surrounded by a small (+2,+2) shadow.
Last updated on 12/25/2010 
by Jean-Damien 
Linked resources
Community comments
  No comments have been posted yet.
© Copyrights
Components used on this web site : Famfamfam icons has been made by Mark James, Rounded corners lite has been coded by Cameron Cooke and Tim Hutchison, SyntaxHighlighter has been written by Alex Gorbatchev. pChart and this web site have been created by Jean-Damien POGOLOTTI. This documentation contains 185 pages and 56 comments. 409 users have registered. This page has been rendered in 0,01 seconds. Wiki revision 1.37.