Copy link to clipboard
Copied
I am attempting to create a news lower third graphic and want the text of the lower third to begin to squeeze closer together when the length of the "headline" hits a certain maximum width, but the font size remains the same.
I have seen this done in Apple Motion but have been struggling to complete it in After Effects.
Any suggestions? I have added an example from CNN to potentially explain better
Drop this into the Transform>Scale prop of the Text Layer -
// calculate textWidth
const myTextWidth_inPixels = thisLayer.sourceRectAtTime(time).width;
// provide edge padding values, for the left and right edges of the panel
const edgesPadding = 50;
// calculate the width of the panel (this scenario uses a Shape Layer's Xsize') add edgepadding
const myTargetWidth = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size[0] - edgesPadding;
// calculate the ratio o
...Copy link to clipboard
Copied
You have to use sourceRectAtTime() to return the width of the text layer, subtract the width of the background, then use that ratio to change the X scale and possibly the Tracking to control the spaces between the letters. You'll also need an If statement to decide when to turn off the resizing.
Copy link to clipboard
Copied
I got part of the way there I am just trying to figure out how to make the tracking value continually make the width fit the maximum. Here is the expression I have so far on the tracking effect:
Copy link to clipboard
Copied
Drop this into the Transform>Scale prop of the Text Layer -
// calculate textWidth
const myTextWidth_inPixels = thisLayer.sourceRectAtTime(time).width;
// provide edge padding values, for the left and right edges of the panel
const edgesPadding = 50;
// calculate the width of the panel (this scenario uses a Shape Layer's Xsize') add edgepadding
const myTargetWidth = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size[0] - edgesPadding;
// calculate the ratio of the text width to the myTargetWidth.
// This value will be used to squash/squish the text if it's width is larger than the myTargetWidth.
const ratioOfText_toTargetWidth = (myTextWidth_inPixels/myTargetWidth);
// use Javascrip ternary (a slimmer ifElse Conditional to check if the ratio of textWidth to targetWidth
ratioOfText_toTargetWidth>1 ? [100/ratioOfText_toTargetWidth,100] : [100,100]
When all is done, you will have to place the position of the text onto the appropriate position; taking into account of the edgePadding you provided earlier. This process can actually be automated but it will also lengthen my post too much for the purpose.
FWIW, for such tasks, it is a good idea that editorial understands the implications of lengthy texts as overly long texts will result in unlegible text. Hence, it is a good idea to provide editorial with guidelines on the max number of lines to use.
HTH
And here's the same Expression without the comments -
const myTextWidth_inPixels = thisLayer.sourceRectAtTime(time).width;
const edgesPadding = 50;
const myTargetWidth = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size[0] - edgesPadding;
const ratioOfText_toTargetWidth = (myTextWidth_inPixels/myTargetWidth);
ratioOfText_toTargetWidth>1 ? [100/ratioOfText_toTargetWidth,100] : [100,100]