Transition: Pixelate through

The old image falls apart into ever coarser blocks and the new one sharpens out of them. The swap happens around the middle, while both are too coarse to tell apart, which is why a plain `pixelate` and `blend` are enough.

A
A — Transition: Pixelate through
B
B — Transition: Pixelate through
Animation
Animation — Transition: Pixelate through
JavaScript
// Pixelate 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: PEAK:integer=32,min=2,max=200

function transition(from, to, T) {
  const k = T < 0.5 ? T * 2 : (1 - T) * 2;        // 0 -> 1 -> 0
  const size = Math.round(1 + k * k * (PEAK - 1));
  // The swap happens only around the middle, while everything is coarse.
  const mix = Math.min(1, Math.max(0, (T - 0.4) / 0.2));
  if (size > 1) {
    from.pixelate(size);
    to.pixelate(size);
  }
  from.blend(to, mix);
  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