Hey guys,
I'm pretty new to expressions but I'm currently trying to set up a template which could potentially have images auto scaled according to the comp size, while still retaining their aspect ratio.
So I've come across this link:
http://aefreemart.com/the-infallible-scale-expression/
The expression he uses is the following:
w = thisLayer.width;
h = thisLayer.height;
compW = thisComp.width;
compH = thisComp.height;
p = thisComp.pixelAspect;
if ( w > h ){ //test if image is taller than wide
s = (compW / w ) * 100;
[ s * p, s ]
}else{
s = (compH / h ) * 100;
[ s , s ]
}
In general it seems to work, however I've had instances where the image still does not fill the composition completely.
Apart from this, I'm having issues when it comes to importing images that are square rather than rectangular. I've tried to include an 'else if' prompt to the expression but haven't managed to figure it out yet.
Does anyone know of a similar expression to the above that is a little more fool-proof?
Also, could anyone help me with including an 'else if' clause for square images?
Thanks and much appreciated.
w = thisLayer.width;
h = thisLayer.height;
compW = thisComp.width;
compH = thisComp.height;
p = thisComp.pixelAspect;
if ( w > h ){ //test if image is taller than wide
s = (compW / w ) * 100;
[ s * p, s ]
}else{
s = (compH / h ) * 100;
[ s , s ]
}