ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Auto-scale text depending upon text length

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Chris Brady
Auto-scale text depending upon text length
on Oct 1, 2019 at 11:16:22 am

Hi all,

Is there a way to auto-scale the text so it fits within a defined area of the composition, no matter the length of text.

Example: The text 'John Smith' sits in the centre of the screen with a padding of 500 pixels either side. When the user changes the name to 'Christopher Smith' the text layer auto-scales down so 500 pixels padding remains either side of the text.

Hope that makes sense. Thanks in advance!

Return to posts index

Andrei Popa
Re: Auto-scale text depending upon text length
on Oct 1, 2019 at 2:33:47 pm

Add this to scale:

var padding = 500;

value * (width-padding*2)/sourceRectAtTime(time,false).width;

To make sure the text stays in the middle, you could add this to the anchorPoint and then press ctrl+home to place it in the middle of the comp.

var myWidth = sourceRectAtTime(time,false).width;
var left = sourceRectAtTime(time,false).left;
var myHeight = sourceRectAtTime(time,false).height;
var top = sourceRectAtTime(time,false).top;

My Envato portfolio.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 All Rights Reserved