Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Dynamic text scale/fontsize up or down base on text length

  • Dynamic text scale/fontsize up or down base on text length

  • Bas v Breugel

    July 13, 2018 at 12:44 pm


    I’ve searched the forum, and found this similar post.
    Scaling text to text box expression
    But the text layer in my project is based on a JSON file, and that doesn’t seem to work with this expression setup.

    So the idea is to have the text size down if it doesn’t fit in the width of the white square. I guess have the expression on the scale parameter works best, you then can parent other text layers so the scale with it?

    This was Kalle’s take on it in above mentioned post.
    txt = value;
    margin = effect("margin")("Slider");
    char_count = txt.length;
    lead_ratio = effect("leading ratio")("Slider");
    rect_height = thisComp.layer("Rect").height*thisComp.layer("Rect").scale[1]/100-2*margin;
    rect_width = thisComp.layer("Rect").width*thisComp.layer("Rect").scale[0]/100-2*margin;
    rect_ratio = rect_width/rect_height;
    char_per_line = Math.round(Math.sqrt(char_count*rect_ratio*lead_ratio));
    lines = Math.ceil(char_count/(char_per_line));
    done = 0;
    esc = 0;
    len =0;
    //row = Math.floor(thisComp.layer("Rect").sourceRectAtTime(time).width*thisComp.layer("Rect").scale[0]/1220);//divisor depends on type size
    row = char_per_line;
    while (done == 0){
    esc ++;
    if (txt.length >= len+1){
    for (i = len; i > len-row; i--) if (txt[i] == " ") break;
    if (i > len-row){
    txt=txt.substr(0,i) + "\r" + txt.substr(i+1,9999);
    len = i;
    if (esc>100){done=1}

  • Kalleheikki Kannisto

    July 23, 2018 at 6:01 am

    This case is significantly simpler. All you need for the scale code in the c_LastName text layer is:

    textwidth = thisLayer.sourceRectAtTime().width;
    s = 100*550/textwidth;

    (“550” is the width of the box you want to limit to. Replace with your desired value.)

    Then you can parent the first name to it. What you want to have is point text, so that it doesn’t wrap onto a new line when it reaches the width of the box like it will with paragraph text.

    Moving the lastname text layer anchor point to the position of the first name top left corner (while the expression is disabled) will keep the alignment at that point.

    You may also want to set a maximum value for the scale (such as 100), so that it doesn’t scale up for shorter names. Min expression works for this. The second line would the become:

    s = Math.min(100*550/textwidth, 100);

    This will help avoid massively large names when they are short, as well as the potential issue of a longer first name (with short last name) extending outside the box.

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Bas v Breugel

    July 25, 2018 at 1:46 pm

    Hienoa! Paljon kiitoksia Kalleheikki! ????????

  • Detlef Maerz

    January 12, 2021 at 1:20 pm

    super nice 👍 Thanks

Viewing 1 - 4 of 4 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy