-
scale up non transparent portion of layer to composition
Hi all, I had 2 precomps working well with 2 seperate codes, and with no surprise I find myself needing a combination of the 2.
Basically, I have a composition that will have a graphic in it ( which will be replaced by the user each time when the client sends one )
I have an expression that auto scales this layer to the composition bounds.
In a different composition, Filip has come up with a great expression that looks for a top edge of a layer.
I now realize that some 3rd party graphics we are receiving have too many transparent pixels around the graphic. So is there a way to re-write this expression so that the graphic will scale up according to non transparent pixels ? I would think the sampleimage part of the code could be worked into the original expression to have the graphic fill the comp even if there are 100 pixels of transparency around the graphic;
the scale to comp code;
x=100*thisComp.width/thisLayer.width;
y=100*thisComp.height/thisLayer.height;
if(x>=y)
[y,y];
else [x,x]
and the find top edge code;
posterizeTime(0);
s=thisComp.layer(“logo”).transform.scale[0]
const l = thisComp.layer(“logo”);
const w = l.width;
const h = l.height;
const heightLog2 = Math.ceil(Math.log(h)/Math.log(2));
const threshold = 1; // on average 1 pixel in a row is opaque to count as the topEdge;
var topEdge = 0;
for(i=heightLog2; i>-1; i–) {
let partition = 2 ** i;
let ss = l.sampleImage([w / 2, topEdge+partition/2], [w / 2, partition/2], false, time);
if (ss[3]<=threshold/(w*partition)) topEdge+=partition;
}
[960, l.toComp([w/2, topEdge])[1] +50 ];
Thanks for any help.