Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Getting layers real bounds using sampleImage()

  • Getting layers real bounds using sampleImage()

    Posted by Arthur Yashin on January 28, 2016 at 8:05 pm

    Hi, forum! I am trying to write an expression that will return a position of the pixel that is furthest to the left side (as an example) and alpha of its color is not equal to zero.

    How I see the algorithm:
    We have a “point” that is located at [0, 0]. We “move” that point down until it hits thisLayer.height ( [0, 1080] for example) and then we add +1 to x value and change y value to 0, so it becomes [1, 0] and so on until the “point” meets the first pixel that has non-zero alpha.

    I suggest this to apply on a point control:
    x=[0, 0];

    do {

    if (x[1]>thisLayer.height) {
    x[0]=x[0]+1
    x[1]=0 }
    else x[1]++
    }
    while (thisLayer.sampleImage(x, [0.5, 0.5]/2, true, time)[3] == 0);

    x
    but it gives error – “Timeout while waiting for the engine”.

    So is it possible to make it work?

    Arthur Yashin replied 10 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Xavier Gomez

    January 29, 2016 at 1:07 am

    If you are on a Text layer or Shape layer, you can use the sourceRectAtTime method, which is way easier to manipulate and also faster.

    For a layer with source (like a solid with a mask etc), to find the left most pixel, you should scan the layer with a verical band that is as high as the layer (ie radius[1] = layer.height). Otherwise with a radius of 0.5 you will need ages to finish.

    Method 1 is to roll that a thin vertical band by increments of 1 until you hit something.

    Method 2 is to start with a sample as big as the layer (so it is not really vertical).
    If you hit, then:

    step0 : you divide the width (radius x) by 2,
    step1 : sample the left part of the image.
    step2 : if you hit, go to step 0 again, with left part of the image,
    else go to step 2, but with the right part.
    And so forth until the radius x becomes smaller than 0.5 (or more if you dont need pixel accuracy);

  • Arthur Yashin

    January 29, 2016 at 1:11 pm

    Thank you very much! Problem is solved

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