GraphicImage Template
drawText()
Draw text into an image
Syntax
Bounds = rb.GraphicImage.drawText(text, startPoint, fontName, fontSize, colour, options)
Parameters
The 'drawText' method takes 6 parameters:
Name | Type/Value | Range/Length | Description | text | string | | Required. The text to write | startPoint | struct Point | see definition | Required. The pixel coordinates of the 'bottom-left' starting point for writing text | fontName | string | | Required. The path to the font-definition file to use for writing this text. See documentation below! | fontSize | number | | Required. The point size for the text | colour | number | | Required. Colour to use for text | options | MetaData | | Optional. Object containing optional values that change how the text is written |
Results
The 'drawText' method returns structure:
Remarks 'draw' a string of text into the image. This method has a number of options that allow
text to be written at angles, selecting a specific font and font size etc. Selecting a fontThe third parameter to this method allows you to identify a font-file, for example a
TTF (True Type) file. For security reasons the fonts you can use are restricted as follows: - Specify a path to the font
If you specify a path (the font parameter contains at least one '/') then the
parameter identifies a specific font file within your virtual servers document root. - Specify just the font file name - no path
If you do not specify a path then the Whitebeam will look in configured 'system'
font areas. These may be well know directories (known and compiled into the
graphics library) or specified by the 'GDFONTPATH' environment variable
The last parameter to this call is an optional set of 'options' expressed as a JavaScript object. To
specify a non-default value for one of these options, include the options object. Currently defined flags are : Option | Default | Description |
---|
antialias | true | If set to 'true', for true-colour images, anti-aliasing of fonts takes place | angle | 0 | Angle the text by a number of degrees (0-360) | boundsCheck | false | Set this option to 'true' to prevent any changes to the image, but to allow
Whitebeam to calculate the bounding rectangle that completely surrounds the text.
Note because text may be angled, the rectangle will also be angled.
Use this, for example, if you want to draw a background then overlay text. |
Example
// Create an empty 500x100 pixel image
var img = (new GraphicImage).create(500,100);
var red = img.colourAlloc(255,0,0);
var blue = img.colourAlloc( 0,0,255);
img.drawText("Hello World", {x:0,y:img.height}, "courier.ttf", 14, blue,
{angle:20 /*degrees*/});
|