Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Automatic font size on text based on its width

  • Automatic font size on text based on its width

    Posted by Svetlin Aleksandrov on June 30, 2020 at 5:30 pm

    Hello,
    I’m trying to make text that decrease its font size depending on its length if its bigger than certain value. I’m trying to use while statement but with no success.

    The idea is lets say we have a text with font size 75 and when you are typing text and the text width reach lets say 500 we want font size to start going down.

    tWidth = thisLayer.sourceRectAtTime().width;
    fSize = 75;

    while(tWidth > 500){
    fSize--;
    thisLayer.text.sourceText.style.setFontSize(fSize);
    tWidth = thisLayer.sourceRectAtTime().width;
    };

    text.sourceText;

    David Avila replied 5 years, 10 months ago 3 Members · 5 Replies
  • 5 Replies
  • Andrei Popa

    July 1, 2020 at 11:12 am

    Is there a particular reason why you don’t decrease the size? If you want to decrease the scale, you can use this as an expression, applied to scale:


    maxWidth = 500;
    thisWidth = sourceRectAtTime(time,false).width;
    ratio = Math.min(maxWidth/thisWidth,1);
    value*ratio

    Andrei
    My Envato portfolio.

  • Svetlin Aleksandrov

    July 1, 2020 at 4:37 pm

    Thanks, that worked in my case. 🙂

  • David Avila

    July 1, 2020 at 4:45 pm

    speaking of font expressions, is there a way to have a text layer reference another layer, and have its own type of font-style-expression? like

    thisComp.layer("Main").text.sourceText.style.setFauxBold(1).setFauxItalic(1).setFontSize(900)

  • Andrei Popa

    July 1, 2020 at 4:59 pm

    Something like

    style.setFauxBold(1).setFauxItalic(1).setFontSize(900).setText(thisComp.layer(“Main”).text.sourceText.value)

    Andrei
    My Envato portfolio.

  • David Avila

    July 1, 2020 at 5:09 pm

    Ahh, thanks.

    I needed to also do it for a long else-if statement. I figured it was the same way, setting the style and the text result in each of the “else if” outputs.

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