You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, subtitle = "A mesmerizing cinematic experience...", subtitleColor = "#ffffff", intensity = 0.85, letterbox = 1, vignette = 0.6) {
// Create an off-screen canvas
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const w = originalImg.width;
const h = originalImg.height;
canvas.width = w;
canvas.height = h;
// Draw the original image onto the canvas
ctx.drawImage(originalImg, 0, 0, w, h);
// Fetch pixel data to apply AI-like cinematic color grading (Teal & Orange)
const imgData = ctx.getImageData(0, 0, w, h);
const data = imgData.data;
const centerX = w / 2;
const centerY = h / 2;
const maxDist = Math.sqrt(centerX * centerX + centerY * centerY);
// Apply color grading per pixel
for (let i = 0; i < data.length; i += 4) {
let r = data[i];
let g = data[i + 1];
let b = data[i + 2];
// Calculate perceived luminance
let lum = 0.299 * r + 0.587 * g + 0.114 * b;
let normLum = lum / 255;
// Teal and Orange cinematic grading formulation
// Shadows are pushed towards Teal (blue/green)
// Midtones/Highlights are pushed towards Orange (red/yellow)
let shadowMix = Math.max(0, 1 - Math.abs(normLum - 0.25) * 2.5);
let highMix = Math.max(0, 1 - Math.abs(normLum - 0.75) * 2.5);
let newR = r + (highMix * 45 - shadowMix * 25) * intensity;
let newG = g + (highMix * 15 + shadowMix * 15) * intensity;
let newB = b + (shadowMix * 45 - highMix * 25) * intensity;
// Cinematic contrast adjustment
const contrast = 1.0 + (0.3 * intensity);
newR = ((newR / 255 - 0.5) * contrast + 0.5) * 255;
newG = ((newG / 255 - 0.5) * contrast + 0.5) * 255;
newB = ((newB / 255 - 0.5) * contrast + 0.5) * 255;
// Apply a subtle vignette effect
if (vignette > 0) {
let px = (i / 4) % w;
let py = Math.floor((i / 4) / w);
let dist = Math.sqrt(Math.pow(px - centerX, 2) + Math.pow(py - centerY, 2));
let vFactor = 1 - (dist / maxDist) * vignette;
// Smoothen the vignette falloff using a power rule
vFactor = Math.pow(vFactor, 0.8);
newR *= vFactor;
newG *= vFactor;
newB *= vFactor;
}
// Clamp values and update data
data[i] = Math.min(255, Math.max(0, newR));
data[i + 1] = Math.min(255, Math.max(0, newG));
data[i + 2] = Math.min(255, Math.max(0, newB));
// alpha (data[i + 3]) is left untouched
}
ctx.putImageData(imgData, 0, 0);
// Apply Cinematic Letterboxing (Classic 2.35:1 Anamorphic Widescreen Aspect Ratio)
let barH = 0;
if (letterbox === 1) {
ctx.fillStyle = '#000000';
const targetAspectRatio = 2.35;
const currentAspectRatio = w / h;
if (currentAspectRatio < targetAspectRatio) {
// Image is too tall, add bars at top and bottom
let viewH = w / targetAspectRatio;
barH = (h - viewH) / 2;
ctx.fillRect(0, 0, w, barH);
ctx.fillRect(0, h - barH - 1, w, barH + 2); // -1/+2 to prevent subpixel bleeding
} else if (currentAspectRatio > targetAspectRatio) {
// Image is too wide, add bars on the left and right
let viewW = h * targetAspectRatio;
let barW = (w - viewW) / 2;
ctx.fillRect(0, 0, barW, h);
ctx.fillRect(w - barW - 1, 0, barW + 2, h);
}
}
// Add Movie Subtitles
if (subtitle && subtitle.trim() !== '') {
// Compute font size based on image width to remain proportionate
let fontSize = Math.max(16, Math.floor(w * 0.035));
ctx.font = `italic 600 ${fontSize}px "Arial", sans-serif`;
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
// Subtitle stroke for legibility over bright scenes
ctx.lineWidth = Math.max(2, fontSize * 0.12);
ctx.lineJoin = 'round';
ctx.strokeStyle = 'rgba(0, 0, 0, 0.9)';
ctx.fillStyle = subtitleColor;
// Calculate text positioning (place softly in the bottom letterbox bar if it exists)
let subY = h - (fontSize * 0.8);
if (letterbox === 1 && barH > (fontSize * 1.5)) {
// Drops down perfectly inside the letterbox bar
subY = h - (barH / 2) + (fontSize * 0.4);
} else if (letterbox === 1 && barH > 0) {
// Placed at the bottom edge of the visible image frame
subY = h - barH - (fontSize * 0.4);
}
// Logic for wrapping text if the subtitle is particularly long
const maxTextWidth = w * 0.85;
const words = subtitle.split(' ');
let line = '';
let lines = [];
for (let n = 0; n < words.length; n++) {
let testLine = line + words[n] + ' ';
let metrics = ctx.measureText(testLine);
if (metrics.width > maxTextWidth && n > 0) {
lines.push(line.trim());
line = words[n] + ' ';
} else {
line = testLine;
}
}
lines.push(line.trim());
// Draw multiple lines from bottom to top
lines.reverse().forEach((l, index) => {
let lineY = subY - (index * (fontSize * 1.3));
ctx.strokeText(l, w / 2, lineY);
ctx.fillText(l, w / 2, lineY);
});
}
return canvas;
}
Apply Changes