{imgtext:width:height:text:size:alignment:color:font:opacity:margin:angle:background:bg_opacity}

Description

Generates an image with text drawn on it and returns a ready-to-use img tag. The image is rendered on demand by the install img.php endpoint using the phpThumb wmt (watermark-text) filter, so the src points at img.php rather than a stored file. width, height and a non-blank text are required - if any is missing imgtext returns an empty string. The remaining parameters control the typography: font size, alignment, text colour, an optional TrueType font, opacity, margin, rotation angle, and a background colour with its own opacity. Because the output embeds the install path and is produced at request time, it is best used inline in templates where an image of a caption, label or watermark is needed without uploading a file.

Parameters

width required

The image width in pixels. Required: imgtext returns an empty string if width, height or text is missing.

height required

The image height in pixels. Required alongside width and text.

text required

The caption to draw on the image. Required and must not be blank after trimming. It is URL-encoded into the request and also copied to the img tag alt attribute.

size optional

Font size. For the built-in font use 1 to 5 (5 is largest); for a TrueType font (see the font parameter) this is the point size. Empty leaves the phpThumb default built-in size.

alignment optional

Where the text sits on the canvas. Use one of the corner/edge/centre codes, * to tile, or an absolute pixel offset written as xoffsetXyoffset (for example 10x20, measured from the top-left corner). Empty places the text top-left.

color optional

Hex colour of the text, without a leading hash (for example cc0000 for red). Empty uses the phpThumb default (black for the built-in font).

font optional

Filename of a TrueType (TTF) font. Empty uses the built-in pixel font. A TTF font is needed for rotation (angle) and for tiling (* alignment) to work fully.

opacity optional

Opacity of the text from 0 (transparent) to 100 (opaque). Empty draws the text fully opaque.

margin optional

Edge margin (and, when tiling, inter-tile margin) as a percentage. Empty uses no extra margin.

angle optional

Rotation angle of the text in degrees. Empty means no rotation. Rotation requires a TrueType font.

background optional default FFFFFF

Hex colour of the background, without a leading hash. This also fills the whole canvas via the new= parameter.

bg_opacity optional default 0

Background opacity from 0 (transparent) to 100 (opaque). With the default 0 the background colour is transparent, so the canvas stays white.

Examples

virtual{imgtext:200:60:Draft copy}
Expected(an img tag whose src is the install img.php endpoint with the wmt filter, width 200, height 60 and alt set to Draft copy; the leading path is install-specific, so this is shown rather than asserted)
ActualDraft copy
Only width, height and text are given; all the styling parameters are left empty. The output is an img tag pointing at the install img.php endpoint, which renders a 200 by 60 PNG on demand: a white background with the built-in pixel font in black, placed top-left. The alt attribute is set to the text.
virtual{imgtext:200:60:Draft copy:4:C:cc0000}
Expected(an img tag for a 200 by 60 PNG: the word Draft copy centred in size-4 red text on a white background)
ActualDraft copy
size 4 picks a larger built-in font (1 to 5), C centres the text, and cc0000 is the hex colour (red, no leading hash). The background stays the default white because background and bg_opacity are omitted.
virtual{imgtext:20:210:My picture text:3:TL:000000::::90}
Expected(an img tag for a 20 by 210 PNG with My picture text drawn top-left, rotated 90 degrees)
ActualMy picture text
The canonical narrow vertical caption from the manual: a 20 by 210 image, font size 3, top-left (TL), black text (000000), with the empty slots for font, opacity and margin skipped, and angle 90 to rotate the text a quarter turn. Rotation needs a TrueType font to take full effect.
virtual{imgtext:300:80:On sale:5:C:FFFFFF::100:::000000:100}
Expected(an img tag for a 300 by 80 PNG: white On sale text centred on a solid black background)
ActualOn sale
To get a solid coloured panel, set background (here 000000, black) and bg_opacity to 100 (fully opaque). The text colour is FFFFFF (white) and its own opacity is 100. Empty slots in between are font and margin, which are left at their defaults. Result: white centred text on a black band.
test{substr:{imgtext:200:60:Draft copy}:0:5}
Expected
Actual
The image itself is install-dependent, so it cannot be asserted directly. Wrapping it in substr and taking the first five characters yields the install-independent tag opener, which confirms imgtext returned an img element rather than an empty string.
test[{imgtext:200:60:}]
Expected[]
Actual[]
imgtext returns an empty string unless all three of width, height and a non-blank text are present. Here the text is empty, so nothing is produced - the brackets show the empty result. The same happens if width or height is missing.