| dynamically sized text boxed
• | | | |
 | dynamically sized text boxed
by brad coomber on Sep 23, 2011 at 10:47:00 am |
Hey All,
So, what I'm trying to achieve is this...
I have a comic book styled project with text/speech boxes. The project will span over 10 different languages so I was planning on feeding After Effects text for each speech box using expressions via a .txt file (utilizing the lower thirds technique).
My problem is the speech/text box sizes - how can I tell After Effects to re size the boxes dynamically according to how much text is inside them? Also I'd need to include a little empty space around the text itself (ie text not touching the inside edges of the box)
Can this be done? Any help would be amazing!
Thanks in advance!
Brad
| | | | |
• | | | |  | Re: dynamically sized text boxed by Dan Ebberts on Sep 23, 2011 at 9:00:26 pm |
There's a clumsy hack where you use sampleImage() to detect the extents of the text. It basically starts at the top of the comp and moves down, one row of pixels at a time looking for the first non-zero alpha. Then it does the same thing bottom up, left-to-right, and right-to-left. There are examples of it in the archives of this forum.
Scripting has a function (sourceRectAtTime) that you can use to directly retrieve the extents of a text layer. If you go the scripting route, that's probably a better way to update your text as well.
Dan
| | | | |
• | | | |  | Re: dynamically sized text boxed by brad coomber on Sep 26, 2011 at 4:13:04 pm |
Thanks Dan,
My scripting isn't the strongest tool in my toolbox - any chance you could point me in the right direction using scripting rather than expressions?
I've played with Nab's sampleImage() code which is very slow - ideally I'd like to get something together that others can just change the text and run the script...
Cheers,
Brad
| | | | |
• | | | |  | Re: dynamically sized text boxed by Dan Ebberts on Sep 26, 2011 at 5:58:36 pm |
Assuming that your text layer is the first layer in the active comp, you would replace the text like this:
var myTextLayer = app.project.activeItem.layer(1);
var mySourceText = myTextLayer.property("Text").property("Source Text");
var myTextDoc = mySourceText.value;
myTextDoc.text = "new text";
mySourceText.setValue(myTextDoc);
Then you can get the extents of the text like this:
var myRect = myTextLayer.sourceRectAtTime(0,true);
At that point, the width of the text is myRect.width, the height is myRect.height, the left edge (relative to the text layer's anchor point) is myRect.left and the top edge is myRect.top. Given that info and the text layer's position, you should be able to size and position the background layer.
Dan
| | | | |
| |
|