This thread is old, but thought I’d add my 2 bits for google’s sake… and for mine if I forget how to write the damn expression. lol.
I use this for NTSC output. Comp of unknown size and image of unknown size. Aspect compensation width only (NTSC) and this assumes square pixel images though I would think you could modify to check and compensate… it would be a pain for legacy aspects. You could also pull the “p” and fix the width (“s”1) by “* 90;”.
w = thisLayer.width;
h = thisLayer.height;
compW = thisComp.width;
compH = thisComp.height;
p = thisComp.pixelAspect;
s1 = (compW / w ) * 100;
s2 = (compH / h ) * 100;
if ( s1 > s2 ){ //test size difference
[ s2 , s2 ]
}else{
[ s1 * p , s1 * p ]
}