View all expressions
Transformation

Auto Scale to Comp

Automatically resizes your image, video, or precomp so it fits perfectly inside the composition. You can choose whether it should fit completely inside (no cropping) or fill the entire frame (may crop a bit). There’s also a switch to keep or ignore the original aspect ratio, so you can decide if it should stay proportional or stretch to fill the space.

Contributed by:


maintainRatio = effect("Maintain Ratio")("Checkbox");
fillMode = effect("Fit / Fill")("Checkbox");
lw = thisLayer.width;
lh = thisLayer.height;
cw = thisComp.width;
ch = thisComp.height;
aspectLayer = lw / lh;
aspectComp = cw / ch;
if (maintainRatio == 1){
if (fillMode == 0){
// FIT (contain without cropping)
scaleFactor = Math.min(cw / lw, ch / lh);
[scaleFactor * 100, scaleFactor * 100];}
else {
// FILL (cover full comp, may crop)
scaleFactor = Math.max(cw / lw, ch / lh);
[scaleFactor * 100, scaleFactor * 100];}}
else {
// No ratio constraint, stretch to fit/fill comp
if (fillMode == 0) {
[cw / lw * 100, ch / lh * 100];
// Fit (stretch)
}
else{
[cw / lw * 100, ch / lh * 100];
// Fill (also stretches in this case)
}}

Auto Scale to Comp

Practical use case

Use this when you’re replacing footage or images in a template and want them to instantly scale to the right size without guessing. It’s great for social-media versions (square, vertical, or widescreen), product videos, or automated projects where every image needs to fit just right every time.

Check out similar expressions

Data-driven video workflows for After Effects are easier with Plainly.

a mesh of elegant lines transparent image