Activity › Forums › Adobe After Effects Expressions › Draw a box around subtitled text?
-
Draw a box around subtitled text?
Posted by Darryl Torke on February 15, 2014 at 7:11 pmI have a layer with text on it that it constantly changing because it is a subtitle. However, my client wants a black box around the text (not just an outline of the text) so it is more legible. Is there anyway I could write a expression to make a box around the text that evaluates each frame and puts a black box, relatively precisely, around the text with, say 20 pixels that border the sides/top+bottom?
Darryl Torke replied 12 years, 3 months ago 2 Members · 6 Replies -
6 Replies
-
Dan Ebberts
February 15, 2014 at 7:26 pmYou could scale a black solid’s width based on the character count of the text, or you could use the sampleImage() hack (search this forum for sampleImage and you should find it) if you need more precision (but it is very inefficient and slow).
You could also do it with a script, but you’d have to run the script whenever you changed the text.
Dan
-
Darryl Torke
February 15, 2014 at 8:56 pmThanks! I used the scale version and it looks pretty good. I have another question though, do you know if using after effects expressions I could find out how many characters are on a certain line of sourcetext? for example, could it return to answer to “how many characters are on line 5 in this body of text?”. Is that within after effects capabilities?
-
Dan Ebberts
February 15, 2014 at 9:03 pmIs it box text? If so, I don’t think so.
If it’s just a text layer with multiple lines, an expression could split the text based on carriage return characters and get the number of characters of any particular line (or the longest line, if that’s what you wanted).
Dan
-
Darryl Torke
February 15, 2014 at 9:13 pmIt is just a text layer with multiple lines, is it possible you could direct me to an example where carriage returns are used to parse out lines? Admittedly this is a bit above my level of understanding. Thank you for your time, no worries if you can’t.
-
Dan Ebberts
February 15, 2014 at 9:31 pmAt the end of this routine, the variable lineMax should contain the number of characters in the longest line:
myText = thisComp.layer("Text Layer").text.sourceText;
splitText = myText.split("\r");
lineMax = 0;
for (var i =0; i < splitText.length; i++){
lineMax = Math.max(lineMax,splitText[i].length);
}
Not that in the second line, there should be a backslash in the quotes, preceding the r, but it probably wont survive the html conversion.
Dan
-
Darryl Torke
February 15, 2014 at 9:56 pmDan, truly. Thank you from the bottom of my heart. Worked like a charm. Your skill is honestly incomparable. Thanks for “giving it forward” to us coding plebs.
Reply to this Discussion! Login or Sign Up