You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, audioFormat = "Opus", volumeNormalization = "-19.0dB/-14.0dB") {
// Creating a canvas to draw the overlay
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// Set canvas size equal to the original image
canvas.width = originalImg.width;
canvas.height = originalImg.height;
// Draw the original image onto the canvas as the background
ctx.drawImage(originalImg, 0, 0);
// Mockup data for YouTube 'Stats for nerds'
const stats = [
{ label: "Video ID / sCPN", value: "jBk4L_xPq1z / 9ZkN3" },
{ label: "Viewport / Frames", value: `${canvas.width}x${canvas.height}*1.00 / 0 dropped` },
{ label: "Current / Optimal Res", value: `${canvas.width}x${canvas.height}@60 / ${canvas.width}x${canvas.height}@60` },
{ label: "Volume / Normalized", value: `100% / 100% (content loudness ${volumeNormalization})` },
{ label: "Codecs", value: `vp09.00.51.08.01.01.01.01.00 (248) / ${audioFormat} (251)` },
{ label: "Color", value: "bt709 / smpte170m" },
{ label: "Host", value: "r4---sn-ab5l6nsk.googlevideo.com" },
{ label: "Connection Speed", value: "54231 Kbps" },
{ label: "Network Activity", value: "0 KB" },
{ label: "Buffer Health", value: "24.5 s" }
];
const padding = 15;
const lineSpacing = 22;
// Set font for measuring text widths
ctx.font = "13px Arial, sans-serif";
let maxLabelWidth = 0;
let maxValueWidth = 0;
// Calculate required width based on text length
stats.forEach(stat => {
const lWidth = ctx.measureText(stat.label).width;
const vWidth = ctx.measureText(stat.value).width;
if (lWidth > maxLabelWidth) maxLabelWidth = lWidth;
if (vWidth > maxValueWidth) maxValueWidth = vWidth;
});
// Box dimensions
const boxWidth = maxLabelWidth + maxValueWidth + padding * 3.5;
const boxHeight = padding * 2.5 + (stats.length + 1) * lineSpacing;
// Handle potential overflow on very small image dimensions
let scale = 1;
if (boxWidth > canvas.width || boxHeight > canvas.height) {
scale = Math.max(0.2, Math.min(canvas.width / (boxWidth + 20), canvas.height / (boxHeight + 20)));
}
ctx.save();
ctx.scale(scale, scale);
const x = 10;
const y = 10;
// Draw slightly transparent dark box for "Stats for nerds" pane
ctx.fillStyle = "rgba(28, 28, 28, 0.85)";
ctx.fillRect(x, y, boxWidth, boxHeight);
// Header - Title
ctx.font = "bold 14px Arial, sans-serif";
ctx.fillStyle = "white";
ctx.fillText("Stats for nerds", x + padding, y + padding + 10);
// Header - Close Button Mockup
ctx.fillStyle = "#888888";
ctx.fillText("X", x + boxWidth - padding - 15, y + padding + 10);
// Draw Stats Details
ctx.font = "13px Arial, sans-serif";
stats.forEach((stat, i) => {
const lineY = y + padding + 10 + (i + 1) * lineSpacing;
// Label Column
ctx.fillStyle = "#aaaaaa";
ctx.fillText(stat.label, x + padding, lineY);
// Value Column
ctx.fillStyle = "#ffffff";
ctx.fillText(stat.value, x + padding * 2.5 + maxLabelWidth, lineY);
});
ctx.restore();
return canvas;
}
Apply Changes