fit_text
Find the largest font size that keeps a string inside a fixed box, preventing text overflow in imagor templates. Returns a font argument for text().
Instructions
Find the largest font size at which a string still fits a box. imagor wraps text but never shrinks it, so a template that suits a short title silently overflows on a longer one. This renders the text on a transparent canvas at candidate sizes, measures the ink, and searches for the largest size that fits. Pass the returned font argument straight to text(). Requires IMAGOR_BASE_URL.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| font | Yes | a Pango font with hyphens for spaces, family first and size last, e.g. Open-Sans-bold or Liberation-Serif-24 | |
| text | Yes | the string to fit; it may contain %0A for a hard line break | |
| color | No | text colour; affects nothing measurable, and defaults to black | |
| max_size | Yes | largest size to try, in points | |
| min_size | No | smallest size to accept; the search stops here and reports that it does not fit | |
| box_width | Yes | width of the area the text has to fit, in pixels | |
| box_height | Yes | height of that area; the wrapped text may not exceed it |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fits | Yes | whether a size at or above min_size fits the box | |
| font | Yes | the font argument to pass to text(), family and size together | |
| note | No | ||
| size | Yes | ||
| lines | Yes | how many lines the text wrapped to at this size | |
| width | Yes | measured ink width in pixels | |
| height | Yes | measured ink height in pixels | |
| probes | Yes | how many renders the search needed |