Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
10.1
10.2
10.3
10.4
10.5
11.0
11.1
11.2
11.3
11.4
Statistic
FMM
Blog
Annotate image (draw text on image).
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
GraphicsMagick | 2.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example | Flags |
---|---|---|---|
ImageRef | The image reference number. | 1 | |
text | Some text | "Hello World" | |
boundingArea | 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" | Optional |
gravity | The position of the text. Can be number of text value. Can be ForgetGravity=0, NorthWestGravity=1, NorthGravity=2, NorthEastGravity=3, WestGravity=4, CenterGravity=5, EastGravity=6, SouthWestGravity=7, SouthGravity=8, SouthEastGravity=9, StaticGravity=10. |
"SouthWestGravity" | Optional |
degrees | The rotation in degrees. | 0 | Optional |
Returns "OK" on success.
NorthWestGravity | 1 | text bottom-left corner placed at top-left |
NorthGravity | 2 | text bottom-center placed at top-center |
NorthEastGravity | 3 | text bottom-right corner placed at top-right |
WestGravity | 4 | text left-center placed at left-center |
CenterGravity | 5 | text center placed at center |
EastGravity | 6 | text right-center placed at right-center |
SouthWestGravity | 7 | text top-left placed at bottom-left |
SouthGravity | 8 | text top-center placed at bottom-center |
SouthEastGravity | 9 | text top-right placed at bottom-right |
StaticGravity | 10 | static |
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.Release";$ref)]
Text and gravity only:
MBS("GMImage.Annotate"; $ref; Annotate Image::Text; ""; "SouthWestGravity")
Write text with Arial Black:
Set Variable [ $ref ; Value: MBS("GMImage.NewFromContainer"; Annotate Image::InputImage) ]
Set Variable [ $r ; Value: MBS("GMImage.SetFontPointsize"; $ref; 72) ]
Set Variable [ $r ; Value: MBS("GMImage.SetFont"; $ref; "Arial Black") ]
Set Variable [ $r ; Value: MBS("GMImage.SetFillColor"; $ref; "RGB 0 0 0") ]
Set Variable [ $r ; Value: MBS("GMImage.Annotate"; $ref; "Hello World"; "100x200+10+80"; 1) ]
Set Field [ Annotate Image::OutputImage ; MBS( "GMImage.WriteToPNGContainer"; $ref ) ]
Set Variable [ $Error ; Value: MBS("GMImage.Release";$ref) ]
Write Japanese text with unicode font and UTF-8 encoding:
# This script loade the original picture to an image environment set the settings for the font and write a text on a picture. Then we save the image in a container.
#
Set Variable [ $ref ; Value: MBS("GMImage.NewFromContainer"; Annotate Image::InputImage) ]
# Settings for the font
Set Variable [ $r ; Value: MBS("GMImage.SetTextEncoding"; $ref; "UTF-8") ]
Set Variable [ $r ; Value: MBS("GMImage.SetFontPointsize"; $ref; 40) ]
Set Variable [ $r ; Value: MBS("GMImage.SetFont"; $ref; "ArialUnicodeMS") ]
Set Variable [ $r ; Value: MBS("GMImage.SetFillColor"; $ref; "RGB 0 0 0") ]
# Write the text to the picture
Set Variable [ $r ; Value: MBS("GMImage.Annotate"; $ref; "Hello こんにちは世界"; "100x200+10+40"; 1) ]
Set Field [ Annotate Image::OutputImage ; MBS( "GMImage.WriteToPNGContainer"; $ref ) ]
# Free image
Set Variable [ $Error ; Value: MBS("GMImage.Free";$ref) ]
Created 18th August 2014, last changed 12nd September 2020
GMImage.Affine - GMImage.AutoOrient
Feedback: Report problem or ask question.