Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to get layer actual width/height with effects applied?

  • How to get layer actual width/height with effects applied?

    Posted by Rafael Braz on November 10, 2022 at 1:21 pm

    I need to calculate the actual size of a text layer in order to centralize it on the screen, but it has a Skew effect and sourceRect returns the dimensions regardless the effect. Is there a way to calculate it?

    I tried to search before posting but this new search tool doesn’t seem very effective. Also I couldn’t limit my search on this forum.

    Rafael Braz replied 3 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    November 10, 2022 at 4:51 pm

    The only other (besides sourceRectAtTime()) tool I know of is sampleImage(). It’s really inefficient because it has to do a lot of calculations, but you can use it to find the non-zero alpha extents of your layer. This expression will give you the left, right, top, and bottom extents. You’ll need to tailor it to your exact requirements.

    L = thisComp.layer("target");
    h = L.height/2;
    w = L.width/2;
    for (i = 0; i < L.width; i++){
    if (L.sampleImage([i,h],[.5,h])[3]>0) break;
    }
    left = i;
    for (i = L.width-1; i >= 0; i--){
    if (L.sampleImage([i,h],[.5,h])[3]>0) break;
    }
    right = i;
    for (i = 0; i < L.height; i++){
    if (L.sampleImage([w,i],[w,.5])[3]>0) break;
    }
    top = i;
    for (i = L.height-1; i >= 0; i--){
    if (L.sampleImage([w,i],[w,.5])[3]>0) break;
    }
    bottom = i;
  • Rafael Braz

    November 10, 2022 at 4:55 pm

    Thanks a lot, Dan. Yea, it seems a lot of calculations. I’m trying to do some workaround. Thanks A LOT anyway. I always learn something reading your answers.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy