Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Mask Path Shape to always match text total scale and width

  • Mask Path Shape to always match text total scale and width

    Posted by Craig Trayler on March 5, 2022 at 12:32 pm

    Hi, I am looking for if possible, a way to have have a mask in a text layer always match the width and height of said text, and also the text will change over time.
    I have seen some talk on linking mask points to positions of other things like nulls, but nothing solid that I can see that would link corner of a point to the top corner of source text.
    I know there are ways with using a second mask layer, but I want this to all be done with one single Text layer.

    Thanks in advance for any help.

    Craig Trayler replied 4 years, 6 months ago 2 Members · 5 Replies
  • 5 Replies
  • Filip Vandueren

    March 5, 2022 at 1:49 pm

    Hi Craig.

    Give the mask this expression:

    sr=sourceRectAtTime();
    pts= [
    [sr.left, sr.top],
    [sr.left+sr.width, sr.top],
    [sr.left+sr.width, sr.top+sr.height],
    [sr.left, sr.top+sr.height],
    ];
    createPath(pts,[],[],true);
  • Craig Trayler

    March 5, 2022 at 3:35 pm

    Hi Filip,
    That is fantastic.
    One more question if I may Filip;
    if I wanted do to the same, but have the corners curved/rounded, would that be possible?
    I would now guess you add in 4 extra points and space them out a small amount and then code in some kind of Bend between two points, maybe linked to a slider of some sort to adjust the bend/curve amount.

  • Filip Vandueren

    March 5, 2022 at 4:53 pm

    Correct, for example like this:

    padding = 15;

    rounding = 30;

    curviness = 1; // 0=chamfer, 1=rounded

    tangentLength = rounding * curviness*.55;

    sr=sourceRectAtTime();

    pts = [

    [sr.left-padding, sr.top-padding+rounding],

    [sr.left-padding+rounding, sr.top-padding],

    [sr.left+sr.width+padding-rounding, sr.top-padding],

    [sr.left+sr.width+padding, sr.top-padding+rounding],

    [sr.left+sr.width+padding, sr.top+sr.height+padding-rounding],

    [sr.left+sr.width+padding-rounding, sr.top+sr.height+padding],

    [sr.left-padding+rounding, sr.top+sr.height+padding],

    [sr.left-padding, sr.top+sr.height+padding-rounding],

    ];

    in_Tangents = [

    [0,0],

    [-1,0]*tangentLength,

    [0,0],

    [0,-1]*tangentLength,

    [0,0],

    [1,0]*tangentLength,

    [0,0],

    [0,1]*tangentLength

    ];

    out_Tangents = [

    [0,-1]*tangentLength,

    [0,0],

    [1,0]*tangentLength,

    [0,0],

    [0,1]*tangentLength,

    [0,0],

    [-1,0]*tangentLength,

    [0,0]

    ];

    createPath(pts,in_Tangents,out_Tangents,true);

  • Filip Vandueren

    March 5, 2022 at 4:54 pm

    If you’re interested, here’s why there’s a multiplication by .55:

    https://stackoverflow.com/questions/1734745/how-to-create-circle-with-b%C3%A9zier-curves

  • Craig Trayler

    March 5, 2022 at 5:53 pm

    Thank you again Filip, code works beautifully and I added some sliders for the padding and rounding. Also that link is a really nice read so far, thanks for that.
    This opens many new doors for me. 🙏 – Craig

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