You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, sensitivityLevel = '15', overlayAlpha = '0.3') {
const sensitivity = Number(sensitivityLevel) || 15;
const alpha = Number(overlayAlpha) || 0.3;
// Create Main Container Wrapper
const container = document.createElement('div');
container.style.display = 'flex';
container.style.flexWrap = 'wrap';
container.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif';
container.style.gap = '20px';
container.style.padding = '20px';
container.style.background = '#f8fafc';
container.style.color = '#334155';
container.style.borderRadius = '12px';
container.style.boxShadow = '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)';
// Image Setup
const imgW = originalImg.width;
const imgH = originalImg.height;
// Create Canvas for Analysis & Display
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d', { willReadFrequently: true });
// Scale for display (restrict max width, preserve aspect ratio)
const maxDisplayWidth = 600;
const scale = imgW > maxDisplayWidth ? maxDisplayWidth / imgW : 1;
canvas.width = imgW;
canvas.height = imgH;
canvas.style.width = `${imgW * scale}px`;
canvas.style.height = `${imgH * scale}px`;
canvas.style.border = '1px solid #cbd5e1';
canvas.style.borderRadius = '8px';
canvas.style.boxShadow = '0 10px 15px -3px rgba(0, 0, 0, 0.1)';
// Flex constraint so it scales nicely
canvas.style.maxWidth = '100%';
canvas.style.objectFit = 'contain';
ctx.drawImage(originalImg, 0, 0);
// Heuristically Detect Semantic Website Blocks based on Visual Edge Profiling
let validSegments = [];
try {
const imgData = ctx.getImageData(0, 0, imgW, imgH).data;
const rowDiffs = new Float32Array(imgH);
// Sum the absolute differences of adjacent horizontal pixels to find edge density
for (let y = 0; y < imgH; y++) {
let rowDiffSum = 0;
for (let x = 0; x < imgW - 1; x++) {
const i = (y * imgW + x) * 4;
const r1 = imgData[i], g1 = imgData[i+1], b1 = imgData[i+2];
const r2 = imgData[i+4], g2 = imgData[i+5], b2 = imgData[i+6];
rowDiffSum += Math.abs(r1 - r2) + Math.abs(g1 - g2) + Math.abs(b1 - b2);
}
// Average edge difference per pixel for this row
rowDiffs[y] = rowDiffSum / (imgW * 3);
}
const segments = [];
let currentSegment = null;
const minGapSize = Math.max(5, Math.floor(imgH * 0.015)); // Blank space needed to split blocks
let gapCount = 0;
// Group rows with content into segments
for (let y = 0; y < imgH; y++) {
if (rowDiffs[y] > sensitivity) {
if (!currentSegment) {
currentSegment = { start: y, end: y };
} else {
currentSegment.end = y;
}
gapCount = 0;
} else {
gapCount++;
if (currentSegment && gapCount >= minGapSize) {
segments.push(currentSegment);
currentSegment = null;
}
}
}
if (currentSegment) {
segments.push(currentSegment);
}
// Filter out isolated noise segments
const minHeight = Math.floor(imgH * 0.03); // Minimum 3% of total height to be considered a major UI block
validSegments = segments.filter(s => (s.end - s.start) >= minHeight);
} catch (e) {
// Fallback in case of Cross-Origin canvas tainting issues
console.warn("CORS issue preventing image analysis. Using fallback schematic block estimation.");
}
// Fallback if the image lacks standard visual web spacing (or if CORS blocked pixel access)
if (validSegments.length === 0) {
// Assume standard 3-tier layout: Header -> Main -> Footer
validSegments = [
{ start: 0, end: Math.floor(imgH * 0.15) },
{ start: Math.floor(imgH * 0.15), end: Math.floor(imgH * 0.85) },
{ start: Math.floor(imgH * 0.85), end: imgH }
];
}
// Setup Analytics Report Wrapper
const reportDiv = document.createElement('div');
reportDiv.style.flex = '1';
reportDiv.style.minWidth = '300px';
reportDiv.style.background = '#ffffff';
reportDiv.style.padding = '24px';
reportDiv.style.borderRadius = '8px';
reportDiv.style.border = '1px solid #e2e8f0';
reportDiv.style.boxShadow = '0 10px 15px -3px rgba(0, 0, 0, 0.1)';
reportDiv.style.display = 'flex';
reportDiv.style.flexDirection = 'column';
let reportHTML = `
<h2 style="margin-top:0; border-bottom: 2px solid #3b82f6; padding-bottom: 12px; color: #1e3a8a; font-size: 1.5rem;">SEO Interface Analysis</h2>
<div style="display: flex; gap: 10px; margin-bottom: 20px;">
<div style="background: #eff6ff; padding: 10px; border-radius: 6px; flex: 1; text-align: center;">
<div style="font-size: 2rem; font-weight: bold; color: #2563eb;">${validSegments.length}</div>
<div style="font-size: 0.85rem; color: #64748b; font-weight: 600;">SEMANTIC BLOCKS</div>
</div>
<div style="background: #f0fdf4; padding: 10px; border-radius: 6px; flex: 1; text-align: center;">
<div style="font-size: 2rem; font-weight: bold; color: #16a34a;">${imgH > 3000 ? 'Low' : 'Good'}</div>
<div style="font-size: 0.85rem; color: #64748b; font-weight: 600;">SCROLL DEPTH</div>
</div>
</div>
<div style="flex: 1; overflow-y: auto; overflow-x: hidden; max-height: 500px; padding-right: 10px;">
<ul style="list-style: none; padding: 0; margin: 0;">
`;
// Process & Annotate each identified semantic interface block
validSegments.forEach((seg, index) => {
const isFirst = index === 0;
const isLast = index === validSegments.length - 1;
const segHeight = seg.end - seg.start;
const heightRatio = segHeight / imgH;
let tagList = '<section>';
let desc = 'Generic Content Wrapper';
let action = 'Check for internal H2/H3 subheadings to ensure logical hierarchy.';
if (isFirst) {
tagList = '<header>, <nav>, <h1>';
desc = 'Navigation / Upper Header';
action = 'Ensure brand logo has alt-text and H1 keyword is present in hero text.';
} else if (isLast) {
tagList = '<footer>';
desc = 'Footer / Secondary Links';
action = 'Include relevant internal site hierarchy links and standard contact schema markup.';
} else if (heightRatio > 0.4) {
tagList = '<main>, <article>, <h2>';
desc = 'Primary Body Elements / Heavy Content';
action = 'Ensure copy thickness is optimal for topic depth; verify image elements within have descriptive alt tags.';
} else {
tagList = '<section>, <aside>, <h3>';
desc = 'Feature Block / Supplementary Content';
action = 'Ensure keyword clustering matches broader SEO context on page intent.';
}
// Draw Canvas Bounding Box Highlight
ctx.fillStyle = `rgba(59, 130, 246, ${alpha})`;
ctx.fillRect(0, seg.start, imgW, segHeight);
ctx.strokeStyle = '#2563eb';
ctx.lineWidth = Math.max(3, Math.floor(imgW * 0.005));
ctx.strokeRect(0, seg.start, imgW, segHeight);
// Draw Canvas Label Container
const labelText = tagList.split(',')[0].replace(/[<>]/g, '').toUpperCase();
ctx.fillStyle = '#1e3a8a';
ctx.fillRect(0, seg.start, imgW > 800 ? 180 : 120, imgW > 800 ? 40 : 30);
// Draw Canvas Label Text
ctx.fillStyle = '#ffffff';
ctx.font = `bold ${imgW > 800 ? '22px' : '16px'} Arial, sans-serif`;
ctx.textBaseline = 'top';
ctx.fillText(` ${labelText} `, 10, seg.start + (imgW > 800 ? 10 : 8));
// Add corresponding report HTML segment
reportHTML += `
<li style="margin-bottom: 16px; padding: 16px; background: #f8fafc; border-left: 4px solid #3b82f6; border-radius: 6px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
<div style="font-size: 1.1em; font-weight: 700; color: #1e3a8a;">
Block ${index + 1}
</div>
<div style="font-size: 0.8rem; background: #e2e8f0; padding: 2px 8px; border-radius: 12px; color: #475569;">
Y: ${seg.start}px - ${seg.end}px
</div>
</div>
<div style="font-size: 0.95em; margin-bottom: 4px;">
<strong>Recommended Tags:</strong> <span style="color: #059669; font-family: monospace;">${tagList.replace(/</g, '<').replace(/>/g, '>')}</span>
</div>
<div style="font-size: 0.9em; margin-bottom: 4px; color: #334155;">
<strong>Archetype:</strong> ${desc}
</div>
<div style="font-size: 0.85em; color: #64748b; margin-top: 8px; font-style: italic;">
<strong>SEO Action:</strong> ${action}
</div>
</li>
`;
});
reportHTML += `</ul></div>`;
reportDiv.innerHTML = reportHTML;
// Append interface parts to container
container.appendChild(canvas);
container.appendChild(reportDiv);
return container;
}
Apply Changes