Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4   7.5    Statistic  

GMImage.Annotate

Annotate image (draw text on image).

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
GraphicsMagick 2.0 Yes Yes Yes Yes Yes

MBS( "GMImage.Annotate"; ImageRef; text { ; boundingArea; gravity; degrees } )

Parameters

Parameter Description Example value
ImageRef The image reference number. 1
text Some text "Hello World"
boundingArea Optional
The rectangle where to draw. Geometry is specified as a width and height "100x200". With an optional offset "100x200+10+20". For percent values, add a percent on the end, for % values add a %: "100x200%!"
"100x200+10+20"
gravity Optional
The position of the text. Can be number of text value.
See table below.
"SouthWestGravity"
degrees Optional
The rotation in degrees.
0

Result

Returns "OK" on success.

Description

Annotate image (draw text on image).
Annotates an image with text. Optionally you can include any of the following bits of information about the image by embedding the appropriate special characters:

%b file size in bytes. %c comment. %d directory in which the image resides. %e extension of the image file. %f original filename of the image. %h height of image. %i filename of the image. %k number of unique colors. %l image label. %m image file format. %n number of images in a image sequence. %o output image filename. %p page number of the image. %q image depth (8 or 16). %p page number of the image. %q image depth (8 or 16). %s image scene number. %t image filename without any extension. %u a unique temporary filename. %w image width. %x x resolution of the image. %y y resolution of the image.

Set a font with full path and @ in front. e.g. "@/Library/Fonts/Arial.ttf". This way the plugin loads it directly.

Gravity values:
NorthWestGravity1text bottom-left corner placed at top-left
NorthGravity2text bottom-center placed at top-center
NorthEastGravity3text bottom-right corner placed at top-right
WestGravity4text left-center placed at left-center
CenterGravity5text center placed at center
EastGravity6text right-center placed at right-center
SouthWestGravity7text top-left placed at bottom-left
SouthGravity8text top-center placed at bottom-center
SouthEastGravity9text top-right placed at bottom-right
StaticGravity10static

You can pass empty text for parameters or not pass parameters. This function can work in 5 modes:
Depending on which parameters you specify or leave empty, we pick the best mode.

The function does not wrap text.
Please use GMImage.FontTypeMetrics to measure how much space text needs.

Examples

Write three lines at 200/200 into the picture:

MBS( "GMImage.Annotate"; $ImageRef; "Hello\nWorld\nAgain"; "200x200"; 0; 0 )

Setup and write Hello:

MBS("GMImage.SetLineWidth"; $img; 1)
MBS("GMImage.SetStrokeColor"; $img; "RGB 0 0 0")
MBS("GMImage.SetFont"; $img; "@/Library/Fonts/Arial.ttf")
MBS("GMImage.SetFontPointsize"; $img; 14)
MBS("GMImage.Annotate"; $img; "Hello World"; "+20+20")

For Windows use different font path:

MBS("GMImage.SetFont"; $img; "@c:\Windows\Fonts\Tahoma.ttf")
MBS("GMImage.Annotate"; $img; "Hello World"; "+20+20")

Load pictures, sets puts text on it in yellow and centered:

# load image from container
Set Variable [$ref; Wert:MBS("GMImage.NewFromContainer"; Annotate Image::InputImage)]
# set font and font size
Set Variable [$r; Wert:MBS("GMImage.SetFontPointsize"; $ref; Annotate Image::FontSize)]
Set Variable [$r; Wert:MBS("GMImage.SetFont"; $ref; Annotate Image::FontPath)]
# set color to yellow
Set Variable [$r; Wert:MBS("GMImage.SetFillColor"; $ref; "RGB 1 1 0")]
# draw in rectangle with width and height of image (here 640 by 480) centered.
Set Variable [$r; Wert:MBS("GMImage.Annotate"; $ref; Annotate Image::Text; "640x480"; "CenterGravity")]
# save image
Set Field [Annotate Image::OutputImage; MBS( "GMImage.WriteToPNGContainer"; $ref )]
# and free memory
Set Variable [$Error; Wert:MBS("GMImage.Destroy";$ref)]

Text and gravity only:

MBS("GMImage.Annotate"; $ref; Annotate Image::Text; ""; "SouthWestGravity")

See also

Example Databases


GMImage.Affine   -   GMImage.AveragePixelValue

Feedback: Report problem or ask question.




Links
MBS Xojo Chart Plugins