Hourglass pinch: columns squeezed at vertical centre

Creates an hourglass-shaped distortion by squeezing the horizontal columns toward the center as they approach the vertical midpoint of the image.

INPUT
INPUT — Hourglass pinch: columns squeezed at vertical centre
OUTPUT
OUTPUT — Hourglass pinch: columns squeezed at vertical centre
JavaScript
// Hourglass pinch: columns squeezed at vertical centre
// warpgrid_squeeze.js
//!INPUT: INPUT
//!OUTPUT: OUTPUT
//!PARAM: PINCH:number=1.2,min=-3.0,max=3.0
//!PARAM: ROWS:number=24,min=2,max=100
//!PARAM: COLS:number=24,min=2,max=100
//!PARAM: TRANS_BORDER:boolean=true

const nodes = {};
for (let r = 0; r < ROWS; r++) {
    const nr = r / (ROWS - 1);
    const row = [];
    // hScale > 1 samples a wider u range → content appears narrower in output
    const hScale = 1 + PINCH * Math.sin(nr * Math.PI);
    for (let c = 0; c < COLS; c++) {
        const nc = c / (COLS - 1);
        // Leave u unclamped so out-of-[0,1] values trigger the chosen
        // border policy (Transparent or Clamp) inside warpGrid.
        const u = 0.5 + (nc - 0.5) * hScale;
        row.push(u, nr);  // v is identity
    }
    nodes[String(r)] = row;
}

Engine.loadImage(INPUT)
    .warpGrid({ rows: ROWS, cols: COLS, nodes, border: TRANS_BORDER ? WarpBorder.Transparent : WarpBorder.Clamp })
    .save(OUTPUT);

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