Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Resizing Text as you’re typing…

  • Resizing Text as you’re typing…

    Posted by Ross Turiano on December 23, 2012 at 2:04 pm

    Hello, I’m still pretty new with expressions.
    I want the text to fit inside a box or shape layer, without having to resize it every time I type a long phrase. Is there anyway to have the text layer automatically resize, as I’m typing it will get smaller and smaller so it fits inside a set parameter or box.
    Basically, the more I type the smaller it will get, so it can fit inside a set box.
    I’m not sure if this is possible, but if it is, Thanks!

    Michael Liu replied 12 years, 3 months ago 4 Members · 9 Replies
  • 9 Replies
  • Dan Ebberts

    December 23, 2012 at 9:58 pm

    This Scale expression should do it. The first line is where you set the desired width.


    nominalWidth = 150;

    for (i = 0; i <= thisComp.width; i++){
    temp = sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2]);
    if (temp[3] > 0) break;
    }
    left = i;

    for (i = thisComp.width; i >= 0; i--){
    temp = sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2]);
    if (temp[3] > 0) break;
    }
    right = i;

    w = right-left;
    if (w > 0)
    value*(nominalWidth/w);
    else
    value

    Dan

  • Armand Verhoeven

    January 25, 2013 at 2:13 pm

    Your expression works Dan except AE have a lot of difficulty after the expression.
    Why is that?

  • Dan Ebberts

    January 25, 2013 at 7:45 pm

    That sampleImage() expression is a hack that chews up a lot of processing time. I would use it only as a last resort.

    Dan

  • Michael Liu

    February 5, 2014 at 9:54 pm

    Hi Dan,

    I’m trying to use the expression you wrote but I can’t figure out how to use it…. Do you add the expression to the scale attribute on the shape or the text?

    Michael

  • Dan Ebberts

    February 5, 2014 at 10:17 pm

    Yes, that’s correct.

    Dan

  • Michael Liu

    February 5, 2014 at 10:20 pm

    It doesn’t seem to be working when I’m writing the text as it’s not auto wrapping the box around the text

  • Michael Liu

    February 5, 2014 at 11:25 pm

    And I may be doing the wrong thing but there doesn’t seem to be any relationship between the shape layer and the text.

    Michael

  • Dan Ebberts

    February 5, 2014 at 11:29 pm

    All the expression does is scale the text to keep it at a fixed width.

    Dan

  • Michael Liu

    February 5, 2014 at 11:49 pm

    I see. Thanks Dan!

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