Transition: Split

The old image splits down the middle and both halves slide away over the new one. Only `crop` and `blendAt`: often the simplest tools give the cleanest cut.

A
A — Transition: Split
B
B — Transition: Split
Animation
Animation — Transition: Split
JavaScript
// Split — 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: CUT:enum(vertical|horizontal)=vertical

function transition(from, to, T) {
  const ease = T * T * (3 - 2 * T);
  const w = to.width, h = to.height;
  const vertical = CUT === "vertical";
  const middle = Math.floor((vertical ? w : h) / 2);
  const away = ease * middle;
  // Fully open, the halves lie outside the frame and only the new image remains.
  if (away < middle) {
    const first = vertical ? from.clone().crop(0, 0, middle, h) : from.clone().crop(0, 0, w, middle);
    const second = vertical
      ? from.clone().crop(middle, 0, w - middle, h)
      : from.clone().crop(0, middle, w, h - middle);
    to.blendAt(first, vertical ? px(-away, 0) : px(0, -away), 1, Blend.Over);
    to.blendAt(second, vertical ? px(middle + away, 0) : px(0, middle + away), 1, Blend.Over);
    first.free();
    second.free();
  }
  from.free();
  return to;
}

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