Nodes/ComfyUI-Book-Tools Nodes for ComfyUI/[Book Tools] Calculate Text Growth
ComfyUI Node

[Book Tools] Calculate Text Growth

A calculator that tells you how much your text needs to grow

By Big-Idea-Technology·Created 2 years ago·Updated 8 months ago· 40
[Book Tools] Calculate Text Growth
    • growth_percentage
    textHello
    mask_width200
    mask_height200
    min_font_size12
    font/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf
    padding50
    line_height_factor1.2

    BTTextGrowth answers one question: "if this text is laid out at the minimum font size, how much would it need to grow to fill the region it's meant to occupy?" The answer comes back as a percentage - 0 to 100 - and there's no image output at all. It's a measurement node, and measurements are what you feed into logic when you want a workflow to make decisions instead of you.

    How it works

    You give it text, the mask_width and mask_height of the region the text should fill, a min_font_size to measure at, and the usual font, padding, line_height_factor. It lays the text out at that minimum size (word-wrapping it within the effective width), measures the resulting width and height, and computes how far short it is:

    • width_ratio = (text_width / mask_width) / 2
    • height_ratio = (text_height / mask_height) / 2
    • take the larger of the two as the growth ratio
    • if that ratio is below 0.5 → return 0
    • otherwise return min(100, int((growth_ratio - 0.5) * 200))

    In plain terms: if the text already fits at minimum size, you get 0; the more the text overflows the region, the higher the percentage climbs, capped at 100.

    The one output is growth_percentage, an INT. It's a pure calculation - no image passes through - so you'll wire it into logic nodes, not into a Save Image.

    Why a beginner would use it

    The obvious home is the loop family. A page renderer that's supposed to end a book when the text no longer fits can do this: measure the growth percentage with BTTextGrowth, compare it against a threshold with a comparison node, and feed the result into BTEndQueue (same pack) to stop the batch. No one sits watching the queue; the workflow stops itself when the text stops fitting.

    It's also useful for scaling: multiply the percentage into a scale/zoom value so a title grows to fill its panel across a series of pages. Think of it as a font-fit estimator you can react to, rather than the auto-fit the overlay nodes do internally.

    The usual caveats

    The font input defaults to the Linux path /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf, which doesn't exist on Windows - the calculation quietly uses PIL's default font and your growth numbers will be off. Point it at a real font (BTDownloadFont is the pack's built-in helper) so the estimate matches what the overlay nodes will actually draw. And remember mask_width / mask_height are the dimensions of the region the text should fill, not the image size - padding is on top of that.

    Installing

    cd ComfyUI/custom_nodes
    git clone https://github.com/Big-Idea-Technology/ComfyUI-Book-Tools
    # restart ComfyUI
    

    Or via ComfyUI Manager: search "ComfyUI-Book-Tools". The pack installs with no models and no extra pip dependencies beyond what ComfyUI already ships.

    Categoryimage/text

    Inputs (7)

    NameTypeDefaultDescription
    textSTRINGHello
    mask_widthINT200
    mask_heightINT200
    min_font_sizeINT121–256
    fontSTRING/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf
    paddingINT50
    line_height_factorFLOAT1.20.5–3

    Outputs (1)

    NameTypeDescription
    growth_percentageINT