Fit to Comp

Scale a layer to fit or fill the comp, maintaining aspect ratio.

Expression Code

// Fit to Comp
// Apply to Scale

mode = "fit";   // "fit" (letterbox) or "fill" (crop)

src = thisLayer.sourceRectAtTime(time, false);
w = thisComp.width / src.width;
h = thisComp.height / src.height;

if (mode == "fit") {
  s = Math.min(w, h);
} else {
  s = Math.max(w, h);
}

[s, s] * 100;
Apply to Scale on any layer. Choose "fit" to see the entire layer (may letterbox) or "fill" to cover the entire comp (may crop edges). The layer scales proportionally.