ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Dynamic Text scaling to fit inside of a shape ?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Joe Wood
Dynamic Text scaling to fit inside of a shape ?
on Jun 1, 2017 at 9:19:06 pm

I am trying to figure out the expressions to make a text layer automatically resize to fit inside of a shape layer or any other layer for that matter.

I know this is possible as I have seen it work in the new essential graphics panel in Premiere, where when you change the text, it automatically resizes to fit an area.

I found some stuff about the "sourceRectAtTime" expression, and it works but it does not constrain proportions.





Any advice?????

// grab sourceRect based on layer time
R = sourceRectAtTime(sourceTime(time), true);

// calculate scale relative to comp
w = thisComp.layer("Shape Layer 1").content("Rectangle Path 1").size[0] / R.width * 100;
h = thisComp.layer("Shape Layer 1").content("Rectangle Path 1").size[1] / R.height * 100;

[w,h]


Return to posts index

Dan Ebberts
Re: Dynamic Text scaling to fit inside of a shape ?
on Jun 1, 2017 at 10:58:26 pm

Try this:

L = thisComp.layer("Shape Layer 1");
rL = L.sourceRectAtTime(time,false);
r = sourceRectAtTime(time,false);
hisUL = L.toComp([rL.left,rL.top]);
hisLR = L.toComp([rL.left+rL.width,rL.top+rL.height]);
myUL = toComp([r.left,r.top]);
myLR = toComp([r.left+r.width,r.top+r.height]);
w = (hisLR[0]-hisUL[0])/(myLR[0]-myUL[0]);
h = (hisLR[1]-hisUL[1])/(myLR[1]-myUL[1]);
[value[0]*w,value[1]*h]


Dan



Return to posts index

Kevin Camp
Re: Dynamic Text scaling to fit inside of a shape ?
on Jun 1, 2017 at 11:04:23 pm

to constrain the proportions, you just need to use the same value for x and y scale... if you wanted to fit to either the height or width, you could use a Math.min() function .
// grab sourceRect based on layer time
R = sourceRectAtTime(sourceTime(time), true);

// calculate scale relative to comp
w = thisComp.layer("Shape Layer 1").content("Rectangle Path 1").size[0] / R.width * 100;
h = thisComp.layer("Shape Layer 1").content("Rectangle Path 1").size[1] / R.height * 100;

s = Math.min ( w, h );

[ s, s ]


Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]