Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Formatting text question in relation to sampleImage Hack

  • Formatting text question in relation to sampleImage Hack

    Posted by Aaron Kent on January 3, 2012 at 10:23 pm

    So I am using the cool sampleImage hack to interactively move a solid based on the length of written type. Its working great for some things but I have an issue. I have two lines of text sometimes. I would like the two lines oftext to be left aligned. The solid is aligned to the left edge. As I type in either line I would the size of the sampleimage to expand from the right side. Sorry if this is confusing. Is there a text formatting expression I can use to do this over the two lines

    Thanks

    AK

    L = thisComp.layer("TYPE HERE");
    for (i = 0; i <= thisComp.width; i++){
    temp = L.sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2],true,time);
    if (temp[3] > 0) break;
    }
    [i-20,value[1]]

    Aaron Kent replied 14 years, 4 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    January 4, 2012 at 4:11 pm

    Something like this, I think:


    rightMargin = 400;

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

    value - [i-rightMargin,0]

    Dan

  • Aaron Kent

    January 5, 2012 at 9:31 pm

    Thanks Dan, I think thats got it working!

    I don’t suppose you be open to doing a line by line breakdown of how the sampleImage hack works? I understand some of the code, but I’d love to fully comprehend the why of this one.

    Either ways Thanks very Much.

    AK

  • Dan Ebberts

    January 5, 2012 at 9:37 pm

    It’s a loop that (in this case) starts at the right edge of the comp and moves left a pixel at a time, sampling an area 1 pixel wide by the height of the comp. As soon as it finds a sample with non-zero alpha, it breaks out of the loop, leaving variable i set to the horizontal pixel corresponding to the right edge of the text.

    Dan

  • Aaron Kent

    January 5, 2012 at 9:39 pm

    awesome, thanks again man. I notice that if you RAM preview this, it jumps around alot, but appears to render out to QT movie rock steady. . .

    AK

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