ImageTools[Draw] - Maple Programming Help

Home : Support : Online Help : Graphics : Image Processing : ImageTools Package : Draw Subpackage : ImageTools/Draw/TextSize

ImageTools[Draw]

 TextSize
 determine the size of ImageTools:-Draw:-Text

 Calling Sequence TextSize( image, text, font, font_size, weight )

Parameters

 image - ImageTools:-Image text - string font - (optional) integer := 14 (roman plain) font_size - (optional) {numeric, [numeric,numeric]} := 12.0 weight - (optional) numeric := 1.0

Description

 • 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.

Package Usage

 • 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(..).

Examples

 > $\mathrm{with}\left(\mathrm{ImageTools}\right):$
 > $\mathrm{with}\left(\mathrm{ImageTools}:-\mathrm{Draw}\right):$

Determining the extent of rendered text.

 > $w,h≔500,120$
 ${w}{,}{h}{≔}{500}{,}{120}$ (5.1)
 > $\mathrm{img}≔\mathrm{Create}\left(h,w,\mathrm{channels}=3,\mathrm{background}=0.5\right):$
 > $\mathrm{msg}≔"Red Box Fits the Text"$
 ${\mathrm{msg}}{≔}{"Red Box Fits the Text"}$ (5.2)
 > $\mathrm{boxW},\mathrm{boxH}≔\mathrm{TextSize}\left(\mathrm{img},\mathrm{msg},\mathrm{font}=10,\mathrm{font_size}=25,\mathrm{weight}=1.5\right)$
 ${\mathrm{boxW}}{,}{\mathrm{boxH}}{≔}{435.659090909091049}{,}{26.5681818181818166}$ (5.3)
 > $\mathrm{x1},\mathrm{y1}≔\frac{w-\mathrm{boxW}}{2},\frac{h-\mathrm{boxH}}{2}$
 ${\mathrm{x1}}{,}{\mathrm{y1}}{≔}{32.1704546}{,}{46.71590909}$ (5.4)
 > $\mathrm{x2},\mathrm{y2}≔\frac{w+\mathrm{boxW}}{2},\frac{h+\mathrm{boxH}}{2}$
 ${\mathrm{x2}}{,}{\mathrm{y2}}{≔}{467.8295454}{,}{73.28409091}$ (5.5)
 > $\mathrm{SolidRectangle}\left(\mathrm{img},\mathrm{x1},\mathrm{y1},\mathrm{x2},\mathrm{y2},\mathrm{color}=\left[0.75,0,0\right]\right)$
 > $\mathrm{Text}\left(\mathrm{img},\frac{w}{2},\frac{h}{2},\mathrm{msg},\mathrm{position}="*",\mathrm{font}=10,\mathrm{font_size}=25,\mathrm{weight}=1.5,\mathrm{color}=1\right)$
 ${25.}{,}{25.}$ (5.6)

Draw a border 5 pixels outside the box.

 > $\mathrm{x1},\mathrm{y1},\mathrm{x2},\mathrm{y2}≔\mathrm{x1}-5,\mathrm{y1}-5,\mathrm{x2}+5,\mathrm{y2}+5$
 ${\mathrm{x1}}{,}{\mathrm{y1}}{,}{\mathrm{x2}}{,}{\mathrm{y2}}{≔}{27.1704546}{,}{41.71590909}{,}{472.8295454}{,}{78.28409091}$ (5.7)
 > $\mathrm{Poly}\left(\mathrm{img},\left[\left[\mathrm{x1},\mathrm{y1}\right],\left[\mathrm{x1},\mathrm{y2}\right],\left[\mathrm{x2},\mathrm{y2}\right],\left[\mathrm{x2},\mathrm{y1}\right],\left[\mathrm{x1},\mathrm{y1}\right]\right],\mathrm{color}="yellow"\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

 > 

Compatibility

 • The ImageTools[Draw][TextSize] command was introduced in Maple 2018.