You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, intensity = '1.0', noiseLevel = '0.1', showOSD = 'true') {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const width = originalImg.width;
const height = originalImg.height;
canvas.width = width;
canvas.height = height;
// Draw original image to canvas
ctx.drawImage(originalImg, 0, 0, width, height);
const intense = parseFloat(intensity) || 1.0;
const noiseLvl = parseFloat(noiseLevel) || 0.1;
const drawText = String(showOSD).trim().toLowerCase() === 'true';
try {
// Pixel manipulation for Chromatic Aberration, VHS Tracking, Grain, and Contrast
const imgData = ctx.getImageData(0, 0, width, height);
const data = imgData.data;
const outData = new Uint8ClampedArray(data.length);
// Horizontal shift amount for the RGB split (chromatic aberration)
const shiftX = Math.max(1, Math.floor((width * 0.005) * intense));
for (let y = 0; y < height; y++) {
// VHS tracking distortion band usually at the bottom 8% of the image
const isTrackingBand = y > height * 0.92;
// Scanline darkening effect (darken every 3rd line)
const scanlineDarken = (y % 3 === 0) ? (1 - (0.15 * intense)) : 1.0;
for (let x = 0; x < width; x++) {
const iOut = (y * width + x) * 4;
// Distortion in the tracking band
let trackingShift = 0;
if (isTrackingBand) {
trackingShift = Math.floor((Math.random() - 0.5) * width * 0.03 * intense);
}
// Calculate the shifted X coordinates for R, G, B channels
const xR = Math.max(0, Math.min(width - 1, x - shiftX + trackingShift));
const xG = Math.max(0, Math.min(width - 1, x + trackingShift));
const xB = Math.max(0, Math.min(width - 1, x + shiftX + trackingShift));
const iR = (y * width + xR) * 4;
const iG = (y * width + xG) * 4;
const iB = (y * width + xB) * 4;
let r = data[iR]; // Red from left-shifted pixel
let g = data[iG + 1]; // Green from center pixel
let b = data[iB + 2]; // Blue from right-shifted pixel
// Add 16mm/VHS analog film grain
const noise = (Math.random() - 0.5) * 255 * noiseLvl;
r += noise;
g += noise;
b += noise;
// Extra white noise static spots in the tracking band
if (isTrackingBand && Math.random() < (0.15 * intense)) {
r += 120;
g += 120;
b += 120;
}
// Apply Contrast curve to imitate old film/tape
const contrast = 1.3;
r = ((r / 255 - 0.5) * contrast + 0.5) * 255;
g = ((g / 255 - 0.5) * contrast + 0.5) * 255;
b = ((b / 255 - 0.5) * contrast + 0.5) * 255;
// Color tint adjustments (Slightly reduced red/blue for a green-ish VHS fade)
r *= 0.9 * scanlineDarken;
g *= 1.0 * scanlineDarken;
b *= 0.9 * scanlineDarken;
outData[iOut] = r;
outData[iOut + 1] = g;
outData[iOut + 2] = b;
outData[iOut + 3] = data[iOut + 3]; // Preserve original alpha
}
}
ctx.putImageData(new ImageData(outData, width, height), 0, 0);
} catch (e) {
console.warn("Canvas ImageData processing failed. Fallback to basic overlays.", e);
}
// Apply Vignette (darkened edges standard in 16mm lens / old TVs)
const gradient = ctx.createRadialGradient(
width / 2, height / 2, 0,
width / 2, height / 2, Math.max(width, height) * 0.75
);
gradient.addColorStop(0, 'rgba(0, 0, 0, 0)');
gradient.addColorStop(1, 'rgba(0, 0, 0, 0.6)');
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, width, height);
// On-Screen Display (OSD) Text imitating a retro HIFI VHS player
if (drawText) {
const fontSize = Math.max(16, Math.floor(Math.min(width, height) * 0.05));
const padding = fontSize;
ctx.font = `bold ${fontSize}px "Courier New", Courier, monospace`;
// Green VCR font styling with CRT glow
ctx.fillStyle = '#00ff00';
ctx.shadowColor = '#00ff00';
ctx.shadowBlur = Math.max(2, fontSize * 0.2);
// Top Left System actions
ctx.textAlign = 'left';
ctx.textBaseline = 'top';
ctx.fillText('PLAY ►', padding, padding);
ctx.fillText('SP', padding, padding + fontSize * 1.3);
// Top Right Audio status
ctx.textAlign = 'right';
ctx.fillText('HIFI STEREO', width - padding, padding);
// Bottom Right Timestamp (above tracking band)
ctx.textBaseline = 'bottom';
// Fixed retro date/time or dynamic based on player vibe
const mockDate = "AM 12:00:00\nJAN 01 1998";
const lines = mockDate.split('\n');
ctx.fillText(lines[0], width - padding, height - (height * 0.1) - (fontSize * 1.2));
ctx.fillText(lines[1], width - padding, height - (height * 0.1));
// Reset shadow
ctx.shadowBlur = 0;
}
return canvas;
}
Apply Changes