ImageTools[Draw]
TextSize
determine the size of ImageTools:-Draw:-Text
Calling Sequence
Parameters
Description
Package Usage
Examples
Compatibility
TextSize( image, text, font, font_size, weight )
image
-
ImageTools:-Image
text
string
font
(optional) integer := 14 (roman plain)
font_size
(optional) {numeric, [numeric,numeric]} := 12.0
weight
(optional) numeric := 1.0
ImageTools:-Draw provides the TextSize function to aid in the manipulation of text. TextSize returns the width and height of a piece of text given a subset of the arguments accepted by the Text primitive
The image parameter is an image created using ImageTools:-Create, or loaded via ImageTools:-Read.
The font argument specifies which of the Hershey fonts to use. This is specified by number, but ImageTools:-Draw exports several symbolic names that can also be used. See ImageTools:-Text for a description of the font numbers and names.
The font_size argument, if given as a single numeric values, specifies the height, in pixels, of the capital letter "X". The size can also be specified as a list of two values, in which case the second value specifies the height. The first value specifies the width, not of a specific glyph, but relative to the second value. For example, font_size=[15,20] specifies than an "X" will be 20 pixels high, and that all glyphs should be scaled to 3/4 of their natural width at the specified height.
The default line weight can be given via the weight argument of the Text primitive. The value of this argument is interpreted as a multiplier for the default weight. Weights in the range of 1.2 to 1.8 will typically result in the glyphs becoming completely filled in. Weights that are too heavy will result in a blurring effect:
The options beginning with font are best provided as keyword equations, but can also be provided as positional arguments starting in the 3rd position as declared in the calling sequence above.
This function is part of the ImageTools:-Draw package, so it can be used in the short form TextSize(..) only after executing the command with(ImageTools:-Draw). However, it can always be accessed through the long form of the command by using ImageTools:-Draw:-TextSize(..).
with⁡ImageTools:
with⁡ImageTools:-Draw:
Determining the extent of rendered text.
w,h≔500,120
img≔Create⁡h,w,channels=3,background=0.5:
msg≔Red Box Fits the Text
boxW,boxH≔TextSize⁡img,msg,font=10,font_size=25,weight=1.5
boxW,boxH≔435.659090909091049,26.5681818181818166
x1,y1≔w−boxW2,h−boxH2
x1,y1≔32.1704546,46.71590909
x2,y2≔w+boxW2,h+boxH2
x2,y2≔467.8295454,73.28409091
SolidRectangle⁡img,x1,y1,x2,y2,color=0.75,0,0
Text⁡img,w2,h2,msg,position=*,font=10,font_size=25,weight=1.5,color=1
25.,25.
Draw a border 5 pixels outside the box.
x1,y1,x2,y2≔x1−5,y1−5,x2+5,y2+5
x1,y1,x2,y2≔27.1704546,41.71590909,472.8295454,78.28409091
Poly⁡img,x1,y1,x1,y2,x2,y2,x2,y1,x1,y1,color=yellow
Embed⁡img
The ImageTools[Draw][TextSize] command was introduced in Maple 2018.
For more information on Maple 2018 changes, see Updates in Maple 2018.
See Also
ImageTools
ImageTools:-Draw:-Circle
ImageTools:-Draw:-Line
ImageTools:-Draw:-Poly
ImageTools:-Draw:-SolidRectangle
ImageTools:-Draw:-Text
Download Help Document