-
Notifications
You must be signed in to change notification settings - Fork 803
Support for multiline text and text wrapping in Caption filter #229
Description
Description
Currently, the Caption filter in Thumbnailator renders text as a single horizontal line. When providing a string containing newline characters (\n) or a string that exceeds the width of the base image, the text is either rendered on one line or cut off at the image boundaries.
I would like to request support for multiline text rendering and/or automatic text wrapping within the Caption filter.
Research Conducted
Before opening this request, I investigated the current library capabilities:
- Searched existing GitHub issues and discussions for "multiline" and "text wrap" but found no native implementation or existing roadmap for this feature.
- Experimented with passing
\ncharacters to theCaptionconstructor, which resulted in the characters being ignored or rendered as a single-line string.
Proposed Behavior
- Manual Line Breaks: The
Captionfilter should recognize\ncharacters and increment the vertical position for subsequent text based on theFontMetricsof the current font. - Automatic Wrapping (Optional but preferred): A way to specify a maximum width (perhaps as a percentage of the image width) where text will automatically wrap to a new line.
Example Use Case
This is particularly useful for generating dynamic image overlays such as:
- Long quotes or product descriptions using non-standard
.ttffonts. - Address blocks where data is naturally split across multiple lines.
- Meme-style captions or informational overlays where the text length is unpredictable.
Current Workaround
The current workaround involves manually creating a BufferedImage via standard Graphics2D and LineBreakMeasurer, then passing that image into the .watermark() method. This breaks the fluent API chain and adds significant boilerplate code.
Are there any plans to implement this in the Caption class?