You can edit the below JavaScript code to customize the image tool.
Apply Changes
async function processImage(originalImg, titleText = "THE RECKONING", releaseText = "COMING SOON") {
// Dynamically load a cinematic font (Oswald)
const fontUrl = "https://fonts.googleapis.com/css2?family=Oswald:wght@400;700&display=swap";
if (!document.querySelector(`link[href="${fontUrl}"]`)) {
const fontLink = document.createElement("link");
fontLink.rel = "stylesheet";
fontLink.href = fontUrl;
document.head.appendChild(fontLink);
}
// Wait for the font API to register the new font
if (document.fonts && document.fonts.ready) {
await document.fonts.ready;
}
// Set up main output canvas for the trailer simulation
const canvas = document.createElement("canvas");
const W = 800;
const H = 450; // 16:9 Aspect Ratio
canvas.width = W;
canvas.height = H;
const ctx = canvas.getContext("2d");
// Generate static noise pattern for film grain effect
const noiseCanvas = document.createElement("canvas");
const NW = 128;
const NH = 128;
noiseCanvas.width = NW;
noiseCanvas.height = NH;
const nctx = noiseCanvas.getContext("2d");
const ndata = nctx.createImageData(NW, NH);
for (let i = 0; i < ndata.data.length; i += 4) {
const val = Math.random() * 255;
ndata.data[i] = val;
ndata.data[i+1] = val;
ndata.data[i+2] = val;
ndata.data[i+3] = 25; // low opacity grain
}
nctx.putImageData(ndata, 0, 0);
const noisePattern = ctx.createPattern(noiseCanvas, "repeat");
// Create a vignette gradient
const vignette = ctx.createRadialGradient(W/2, H/2, W/4, W/2, H/2, W/1.5);
vignette.addColorStop(0, "rgba(0,0,0,0)");
vignette.addColorStop(1, "rgba(0,0,0,0.85)");
let startTime = null;
// Animation Loop
function renderFrame(timestamp) {
if (!startTime) startTime = timestamp;
const elapsed = (timestamp - startTime) / 1000; // in seconds
const DURATION = 12; // Total sequence loop duration
const t = elapsed % DURATION;
// Clear frame
ctx.clearRect(0, 0, W, H);
if (t < 2.5) {
// Stage 1: MPAA Green Band Screen
ctx.fillStyle = "#127131";
ctx.fillRect(0, 0, W, H);
ctx.fillStyle = "white";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "bold 20px Arial";
ctx.fillText("THE FOLLOWING PREVIEW HAS BEEN APPROVED FOR", W/2, H/2 - 30);
ctx.font = "bold 36px Arial";
ctx.fillText("ALL AUDIENCES", W/2, H/2 + 10);
ctx.font = "12px Arial";
ctx.fillText("BY THE MOTION PICTURE ASSOCIATION OF AMERICA", W/2, H/2 + 50);
} else if (t < 4.5) {
// Stage 2: Intro Cinematic Text
ctx.fillStyle = "black";
ctx.fillRect(0, 0, W, H);
ctx.fillStyle = "white";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "400 40px Oswald, sans-serif";
// Fade in/out logic
const fade = Math.min(1, Math.max(0, (t - 2.5) * 2)) * Math.min(1, Math.max(0, (4.5 - t) * 2));
ctx.globalAlpha = fade;
ctx.fillText("IN A WORLD...", W/2, H/2);
ctx.globalAlpha = 1.0;
} else if (t < 9.5) {
// Stage 3: The "AI" Trailerized Photo shot with Ken Burns effect
const p = (t - 4.5) / 5.0; // Normalized time 0.0 -> 1.0
const fade = Math.min(1, p * 4) * Math.min(1, (1 - p) * 4);
ctx.save();
ctx.globalAlpha = fade;
// Background color for underlying fill
ctx.fillStyle = "#050a12";
ctx.fillRect(0, 0, W, H);
// Calculate Ken Burns variables (Slow zoom + drifting pan)
const zoomOrigin = 1.05;
const zoomAmount = p * 0.15;
const scale = zoomOrigin + zoomAmount;
const driftX = Math.sin(p * Math.PI) * 15;
const driftY = Math.cos(p * Math.PI) * -10;
ctx.translate(W/2 + driftX, H/2 + driftY);
ctx.scale(scale, scale);
// Calculate cover image dimensions
const iw = originalImg.width;
const ih = originalImg.height;
const iratio = iw / ih;
const cratio = W / H;
let dw, dh;
if (iratio > cratio) {
dh = H;
dw = H * iratio;
} else {
dw = W;
dh = W / iratio;
}
// Draw original Image
ctx.drawImage(originalImg, -dw/2, -dh/2, dw, dh);
// Cinematic Color Grade (Teal/Orange Split Tone Simulation)
ctx.globalCompositeOperation = "overlay";
ctx.fillStyle = "rgba(40, 80, 150, 0.4)";
ctx.fillRect(-dw/2, -dh/2, dw, dh);
ctx.globalCompositeOperation = "source-over";
ctx.restore();
// Draw Vignette
ctx.fillStyle = vignette;
ctx.fillRect(0, 0, W, H);
// Overlay Cinematic Title & Details
if (t > 6) {
const textFade = Math.min(1, (t - 6) / 2) * fade;
ctx.save();
ctx.globalAlpha = textFade;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
// Title shadow & main text
ctx.shadowColor = "rgba(0, 0, 0, 0.8)";
ctx.shadowBlur = 15;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 4;
ctx.fillStyle = "white";
ctx.font = "700 65px Oswald, sans-serif";
ctx.letterSpacing = "6px";
ctx.fillText(titleText.toUpperCase(), W/2, H/2 - 20);
// Subtitle/Release Date
ctx.font = "400 28px Oswald, sans-serif";
ctx.fillStyle = "#cca870"; // cinematic gold cast
ctx.letterSpacing = "10px";
ctx.fillText(releaseText.toUpperCase(), W/2, H/2 + 45);
ctx.restore();
}
} else {
// Stage 4: Outro Black Screen
ctx.fillStyle = "black";
ctx.fillRect(0, 0, W, H);
}
// Global Overlays (Apply permanently across all frames)
// 1. Letterboxing (Cinematic Crop 2.35:1)
const barHeight = H * 0.12;
ctx.fillStyle = "black";
ctx.fillRect(0, 0, W, barHeight);
ctx.fillRect(0, H - barHeight, W, barHeight);
// 2. Animated Film Grain
ctx.save();
// Give the noise canvas random translation for flicker effect
ctx.translate(-Math.random() * NW, -Math.random() * NH);
ctx.fillStyle = noisePattern;
ctx.globalCompositeOperation = "multiply";
ctx.fillRect(0, 0, W + NW, H + NH);
ctx.restore();
// Loop request
canvas.animId = requestAnimationFrame(renderFrame);
}
// Start sequence
canvas.animId = requestAnimationFrame(renderFrame);
// Return the living Canvas element which simulates the video output
return canvas;
}
Apply Changes