-
Motion Boutique – Text Bounds Expression
I’d like to alter the existing expression to only evaluate the time at start.
If the text doesn’t change, you can save render time by evaluating the expression at t=0 only. It is recommended to Convert Expression to Keyframes when you’re done with the text layer.
thanks.
step = 1; // higher values speed things up (2 means two times faster) but reduce precision
L = thisComp.layer("MyTextLayer"); // text layer whose size must be evaluatedw = thisComp.width;
h = thisComp.height;
halfW = w / 2;
halfH = h / 2;
halfStep = step / 2;left = w;
right = 0;
top = h;
bottom = 0;// find left
found = false;
for (x = 0; !found && x < w; x+=step)
{
if (L.sampleImage([x,halfH], [halfStep,halfH], true)[3] > 0)
{
found = true;
if (x < left)
left = x;
}
}
// find right
found = false;
for (x = w; !found && x >= 0; x-=step)
{
if (L.sampleImage([x,halfH], [halfStep,halfH], true)[3] > 0)
{
found = true;
if (x > right)
right = x;
}
}
// find top
found = false;
for (y = 0; !found && y < h; y+=step)
{
if (L.sampleImage([halfW,y], [halfW,halfStep], true)[3] > 0)
{
found = true;
if (y < top)
top = y;
}
}
// find bottom
found = false;
for (y = h; !found && y >= 0; y-=step)
{
if (L.sampleImage([halfW,y], [halfW,halfStep], true)[3] > 0)
{
found = true;
if (y > bottom)
bottom = y;
}
}/*"Size of textn" + (right-left) + "x" + (bottom-top)*/
left + "," + top + "," + (right-left) + "," + (bottom-top)