Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Change font size or scale of lines based on number of characters in each line

  • Change font size or scale of lines based on number of characters in each line

    Posted by TIneke Van Schalkwyk on February 10, 2023 at 4:19 am

    Change font size or scale of lines based on number of characters in the line. I have text over multiple keyframes (markers) to be used as captions and want to create some randomness to the font size.

    I would be using 3 sizes:
    >7, 120
    between 7 and 12, 100
    <12, 80

    For example in the following text the two lines would end up with different font sizes (or scale):

    My own
    experience

    I tried creating this code with just 2 varibles to keep it simple to start with but

    lines = thisLayer.text.sourceText.split(“/\r\n|\r|\n/”);

    for (i = 0; i < lines.length; i++) {

    if (lines[i].length < 9) {

    [120, 120];

    } else {

    [100, 100];

    }

    TIneke Van Schalkwyk replied 3 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Filip Vandueren

    February 10, 2023 at 9:20 am

    Hoi Tineke,

    since we can’t change the font size per line, we’d have to do it with a text animator.

    The example you chose works well since a 120% scale applies at amount -100 will give 80% scale.

    here’s the recipe:

    – Add a text animator for Scale

    – set the scale value to 120

    – give it an expression selector based on lines

    – give it this expression:

    lines = thisLayer.text.sourceText.value.split(/\r\n|\r|\n|\x03/);
    l = lines[textIndex-1].length;
    if (l<7) {
    100;
    } else if (l<12) {
    0
    } else {
    -100;
    }

    Don’t forget to set the text’s Anchor Point grouping to Line also (Text -> More options) otherwise only the individual characters will become smaller in place.

    Depending on your paragraph alignment, you might also need to adjust the Grouping Alignment ([0,0] for centered text, [-100,0] for left aligned, [100,0] for right aligned)

    NB: I’ve also added \x03 to the linesplitter, that’s the character After Effects uses for a soft linebreak (shift-enter)

  • TIneke Van Schalkwyk

    February 10, 2023 at 8:58 pm

    Thank you Flip!

    Those extra notes were what I was missing.
    Works perfectly!

    “Don’t forget to set the text’s Anchor Point grouping to Line also (Text -> More options) otherwise only the individual characters will become smaller in place.

    Depending on your paragraph alignment, you might also need to adjust the Grouping Alignment ([0,0] for centered text, [-100,0] for left aligned, [100,0] for right aligned)”

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