Transition: Zoom through

The old image grows and fades while the new one rises from the centre, as if you walked through it. Both zooms are one `warpPerspective` with a matrix built around the middle of the image.

A
A — Transition: Zoom through
B
B — Transition: Zoom through
Animation
Animation — Transition: Zoom through
JavaScript
// Zoom through — one transition between two photos, exported as a looping animated WebP.
//
// Everything specific sits in transition(from, to, T): it takes two images it may change and a
// progress T from 0 to 1, and returns one new frame. Video tools can call exactly that for each
// frame of a cut; the rest of this script only builds the animation.

//!INPUT: A, B
//!OUTPUT: OUT
//!PARAM: STEPS:integer=18,min=2,max=120
//!PARAM: DELAY_MS:integer=50,min=10,max=2000
//!PARAM: HOLD_MS:integer=700,min=0,max=5000
//!PARAM: GROW:number=0.25,min=0,max=1,step=0.05
//!PARAM: START:number=0.8,min=0.1,max=1,step=0.05

function transition(from, to, T) {
  const ease = T * T * (3 - 2 * T);
  const w = to.width, h = to.height;
  // Scale by z around the centre of the image.
  const around = (z) => [z, 0, (1 - z) * w / 2, 0, z, (1 - z) * h / 2, 0, 0, 1];
  from.warpPerspective(w, h, around(1 + GROW * ease), Interp.Bilinear, WarpBorder.Clamp);
  to.warpPerspective(w, h, around(START + (1 - START) * ease), Interp.Bilinear, WarpBorder.Clamp);
  from.blend(to, ease);
  to.free();
  return from;
}

const imgA = Engine.loadImage(A);
const imgB = Engine.loadImage(B);
if (imgB.width !== imgA.width || imgB.height !== imgA.height) {
  imgB.resize(imgA.width, imgA.height);
}
const anim = Engine.animation(imgA.width, imgA.height, { loop: 0 });
const p = Engine.progress("Transition frames", { total: STEPS * 2 });

// There and back: the loop closes without a jump, and both directions show the effect.
for (const [first, second] of [[imgA, imgB], [imgB, imgA]]) {
  for (let i = 0; i < STEPS; i++) {
    const T = i / (STEPS - 1);
    const frame = transition(first.clone(), second.clone(), T);
    anim.addFrame(frame, { delay: i === STEPS - 1 ? HOLD_MS : DELAY_MS });
    frame.free();
    p.step(1, `frame ${i + 1}/${STEPS}`);
  }
}

anim.saveWebP(OUT, { lossy: true, quality: 62 });
anim.free();
imgA.free();
imgB.free();

// © 2026 Michael Lechner · mlc OpticScript · https://mlcgo.eu · Elastic License 2.0