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
\n characters to the Caption constructor, which resulted in the characters being ignored or rendered as a single-line string.
Proposed Behavior
- Manual Line Breaks: The
Caption filter should recognize \n characters and increment the vertical position for subsequent text based on the FontMetrics of 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
.ttf fonts.
- 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?
Description
Currently, the
Captionfilter 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
Captionfilter.Research Conducted
Before opening this request, I investigated the current library capabilities:
\ncharacters to theCaptionconstructor, which resulted in the characters being ignored or rendered as a single-line string.Proposed Behavior
Captionfilter should recognize\ncharacters and increment the vertical position for subsequent text based on theFontMetricsof the current font.Example Use Case
This is particularly useful for generating dynamic image overlays such as:
.ttffonts.Current Workaround
The current workaround involves manually creating a
BufferedImagevia standardGraphics2DandLineBreakMeasurer, 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
Captionclass?