GMImage.DrawLine
----------------

Draws a line.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [GraphicsMagick](component_GraphicsMagick.md) | [3.0](newinversion30.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "GMImage.DrawLine"; ImageRef; StartX; StartY; endX; endY ) 

**MBS**( **"GMImage.DrawLine";** /\* Draws a line. \*/  
**$ImageRef**; /\* The image reference number.e.g. 1 \*/   
**$StartX**; /\* The start X position. \*/   
**$StartY**; /\* The start Y position. \*/   
**$endX**; /\* The end X position. \*/   
**$endY**) /\* The end Y position. \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| ImageRef | The image reference number. | 1 |
| StartX | The start X position. |  |
| StartY | The start Y position. |  |
| endX | The end X position. |  |
| endY | The end Y position. |  |

### Result

Returns OK or error message.

### Description

Draws a line.  
Draw a line using stroke color and thickness using starting and ending coordinates.  
  
If you have an open path, the command is added there for later drawing with [GMImage.DrawPath](GMImageDrawPath.md).  
### Examples

Create an image with a line:

 Set Variable \[ $img ; Value:MBS ("[GMImage.New](GMImageNew.md)"; "300x200"; "RGB 1 1 1") \]  
Set Variable \[ $r ; Value:MBS ("[GMImage.SetStrokeColor](GMImageSetStrokeColor.md)"; $img ; "RGB 1 0 0") \]   
Set Variable \[ $r ; Value:MBS ("[GMImage.SetFillColor](GMImageSetFillColor.md)"; $img ; "RGB 0 0 1") \]  
Set Variable \[ $r ; Value:MBS ("[GMImage.SetLineWidth](GMImageSetLineWidth.md)"; $img ; 5) \]  
Set Variable \[ $r ; Value:MBS ("GMImage.DrawLine"; $img ; 50; 50; 250; 150) \]  
Set Variable \[ $png ; Value:MBS ("[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; $img ; "test.png") \]   
Set Variable \[ $r ; Value:MBS ("[GMImage.Release](GMImageRelease.md)"; $img ) \]  
Set Field \[ Drawing::Image ; $png \]  
Draw a line from pos to pos2 on column x:

 MBS ( "GMImage.DrawLine"; $img ; $x ; $pos ; $x ; $pos2 )  
Draw bar charts:

 Set Field \[ MyChart::Chart ;   
  
Let ( \[  
  
 cities = List ( "Hamburg" ; "Berlin" ; "Munich" ; "Cologne" ) ;  
 values = List ( 1800000 ; 3700000 ; 1500000 ; 1100000 ) ;  
  
 colors = List ( "#4e79a7" ; "#f28e2b" ; "#e15759" ; "#76b7b2" ; "#59a14f" ) ;  
  
 img = MBS ( "[GMImage.New](GMImageNew.md)"; "600x400"; "white" ) ;  
  
 maxValue = Max ( 1800000 ; 3700000 ; 1500000 ; 1100000 ) ;  
  
 r = MBS ( "[GMImage.SetStrokeColor](GMImageSetStrokeColor.md)"; img; "black" ) ;  
 r = MBS ( "GMImage.DrawLine"; img; 50; 350; 550; 350 ) ; // X-axis  
 r = MBS ( "GMImage.DrawLine"; img; 50; 50; 50; 350 ) ; // Y-axis  
  
 barWidth = 80 ;  
 spacing = 30 ;  
 baseX = 70 ;  
  
 r = Let ( \[  
 count = ValueCount ( cities ) ;  
 colorCount = ValueCount ( colors ) ;  
 r = While (  
 \[ i = 1 \] ; i ≤ count ;  
 \[  
 city = GetValue ( cities ; i ) ;  
 val = GetValue ( values ; i ) ;  
 color = GetValue ( colors ; Mod ( i - 1 ; colorCount ) + 1 ) ;  
  
 height = (val / maxValue) \* 300 ;  
 x1 = baseX + (i - 1) \* (barWidth + spacing) ;  
 x2 = x1 + barWidth ;  
 y1 = 350 - height ;  
 y2 = 350 ;  
  
 r = MBS ( "[GMImage.SetFillColor](GMImageSetFillColor.md)"; img; color ) ;  
 r = MBS ( "[GMImage.DrawRectangle](GMImageDrawRectangle.md)"; img; x1; y1; x2; y2 ) ;  
 r = MBS ( "[GMImage.SetFontPointSize](GMImageSetFontPointSize.md)"; img; 16 );  
   
 geometry = barWidth &amp; "x20+" &amp; x1 &amp; "+360" ;  
 r = MBS ( "[GMImage.Annotate](GMImageAnnotate.md)"; img; city; geometry; 5 ) ; // 5 = CenterGravity  
  
 i = i + 1  
 \] ; r  
 )  
 \] ; r ) ;  
  
 result = MBS ( "[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; img; "test.png" );  
 r = MBS ("[GMImage.Free](GMImageFree.md)"; img)  
   
\] ; result ) \]  
### See also

- [GMImage.Annotate](GMImageAnnotate.md)
- [GMImage.DrawCircle](GMImageDrawCircle.md)
- [GMImage.DrawPath](GMImageDrawPath.md)
- [GMImage.DrawRectangle](GMImageDrawRectangle.md)
- [GMImage.New](GMImageNew.md)
- [GMImage.Release](GMImageRelease.md)
- [GMImage.SetFillColor](GMImageSetFillColor.md)
- [GMImage.SetFont](GMImageSetFont.md)
- [GMImage.SetLineWidth](GMImageSetLineWidth.md)
- [GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)

### Example Databases

- [GraphicsMagick/Drawing](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Drawing.shtml#1ScriptAnchor_)
- [GraphicsMagick/Find Pixels](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Find%20Pixels.shtml#1ScriptAnchor_)
- [GraphicsMagick/ProgressBar in Portal](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/ProgressBar%20in%20Portal.shtml#13010FieldAnchor_)

### Blog Entries

- [Self made charts in FileMaker](https://www.mbsplugins.de/archive/2025-06-26/Self_made_charts_in_FileMaker/monkeybreadsoftware_blog_filemaker)
- [Custom progress bars for FileMaker](https://www.mbsplugins.de/archive/2024-04-10/Custom_progress_bars_for_FileM/monkeybreadsoftware_blog_filemaker)
- [GraphicsMagick in FileMaker, part 20](https://www.mbsplugins.de/archive/2022-12-20/GraphicsMagick_in_FileMaker_pa/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th August 2014 , last changed 25th February 2026

  
[GMImage.DrawEllipse](GMImageDrawEllipse.md) - [GMImage.DrawPath](GMImageDrawPath.md)

[HTML Version](GMImageDrawLine.shtml)