You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, topic = 'Web Interface Experience') {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// Set high-resolution fixed dimensions to match a typical browser viewport
const width = 1200;
const height = 900;
canvas.width = width;
canvas.height = height;
// Draw solid background
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, width, height);
// Helpers
function drawRoundRect(ctx, x, y, w, h, radius, fill, stroke) {
if (typeof radius === 'number') {
radius = {tl: radius, tr: radius, br: radius, bl: radius};
} else {
const defaultRadius = {tl: 0, tr: 0, br: 0, bl: 0};
for (let side in defaultRadius) {
radius[side] = radius[side] === undefined ? defaultRadius[side] : radius[side];
}
}
ctx.beginPath();
ctx.moveTo(x + radius.tl, y);
ctx.lineTo(x + w - radius.tr, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + radius.tr);
ctx.lineTo(x + w, y + h - radius.br);
ctx.quadraticCurveTo(x + w, y + h, x + w - radius.br, y + h);
ctx.lineTo(x + radius.bl, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - radius.bl);
ctx.lineTo(x, y + radius.tl);
ctx.quadraticCurveTo(x, y, x + radius.tl, y);
ctx.closePath();
if (fill) ctx.fill();
if (stroke) ctx.stroke();
}
function wrapText(ctx, text, x, y, maxWidth, lineHeight) {
const words = text.split(' ');
let line = '';
let currentY = y;
for (let n = 0; n < words.length; n++) {
const testLine = line === '' ? words[n] + ' ' : line + words[n] + ' ';
const metrics = ctx.measureText(testLine);
const testWidth = metrics.width;
if (testWidth > maxWidth && line !== '') {
ctx.fillText(line, x, currentY);
line = words[n] + ' ';
currentY += lineHeight;
} else {
line = testLine;
}
}
ctx.fillText(line, x, currentY);
return currentY;
}
// 1. Draw Mac-like Browser Window Header
ctx.fillStyle = '#f1f3f4';
ctx.fillRect(0, 0, width, 60);
const macColors = ['#ff5f56', '#ffbd2e', '#27c93f'];
macColors.forEach((color, i) => {
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(24 + i * 24, 30, 6, 0, Math.PI * 2);
ctx.fill();
});
// Browser URL Bar container
ctx.fillStyle = '#ffffff';
drawRoundRect(ctx, 150, 14, 900, 32, 16, true, false);
ctx.fillStyle = '#5f6368';
ctx.font = '14px Arial, sans-serif';
let url = "https://www.google.com/search?q=" + encodeURIComponent(topic);
ctx.fillText(url, 170, 35, 860);
// Separator line between browser header and web content
ctx.beginPath();
ctx.moveTo(0, 60);
ctx.lineTo(width, 60);
ctx.strokeStyle = '#cccccc';
ctx.stroke();
// 2. Draw Google Search Nav Header
// Multi-colored text logo
ctx.font = 'bold 36px Arial, sans-serif';
const logoColors = ['#4285F4', '#EA4335', '#FBBC05', '#4285F4', '#34A853', '#EA4335'];
const letters = 'Google'.split('');
let currentX = 40;
letters.forEach((l, i) => {
ctx.fillStyle = logoColors[i];
ctx.fillText(l, currentX, 114);
currentX += ctx.measureText(l).width - 1;
});
// Main Search Input Box
ctx.shadowColor = 'rgba(0,0,0,0.1)';
ctx.shadowBlur = 6;
ctx.shadowOffsetY = 2;
ctx.fillStyle = '#ffffff';
drawRoundRect(ctx, 160, 80, 640, 46, 23, true, false);
ctx.shadowColor = 'transparent';
ctx.strokeStyle = '#dfe1e5';
drawRoundRect(ctx, 160, 80, 640, 46, 23, false, true);
// Search Box Magnifying Glass Icon
ctx.strokeStyle = '#9aa0a6';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(766, 101, 6, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(770, 105);
ctx.lineTo(776, 111);
ctx.stroke();
ctx.lineWidth = 1;
// Search Topic Text inside input box
ctx.fillStyle = '#202124';
ctx.font = '16px Arial, sans-serif';
ctx.fillText(topic, 180, 109, 560);
// Navigation Tabs Categories
ctx.fillStyle = '#1a73e8';
ctx.font = 'bold 14px Arial, sans-serif';
ctx.fillText("All", 160, 166);
ctx.fillRect(160, 177, 20, 3); // Active Blue Underline
ctx.fillStyle = '#5f6368';
ctx.font = '14px Arial, sans-serif';
ctx.fillText("Images", 210, 166);
ctx.fillText("News", 280, 166);
ctx.fillText("Videos", 340, 166);
ctx.fillText("Books", 410, 166);
ctx.fillText("More", 470, 166);
ctx.beginPath();
ctx.moveTo(0, 180);
ctx.lineTo(width, 180);
ctx.strokeStyle = '#ebebeb';
ctx.stroke();
// 3. Draw Main Search Results (Left Side)
let resY = 230;
const dummyDomainColors = ['#f4b400', '#0f9d58', '#4285f4', '#db4437'];
for (let i = 1; i <= 4; i++) {
// Mock site Favicon
ctx.fillStyle = dummyDomainColors[i - 1];
ctx.beginPath();
ctx.arc(168, resY - 4, 8, 0, Math.PI * 2);
ctx.fill();
// Breadcrumb Title
ctx.fillStyle = '#202124';
ctx.font = '14px Arial, sans-serif';
ctx.fillText("Resource Insight Site " + i, 184, resY);
// Breadcrumb URL string
ctx.fillStyle = '#4d5156';
ctx.font = '12px Arial, sans-serif';
ctx.fillText("https://www.resourcesite" + i + ".com › " + topic.replace(/\s/g, '-').toLowerCase(), 160, resY + 20);
// Subresult Clickable Anchor Title
ctx.fillStyle = '#1a0dab';
ctx.font = 'normal 20px Arial, sans-serif';
ctx.fillText(topic + " - Essential Information and Guidelines", 160, resY + 46, 600);
// Detailed Text Description Snippet
ctx.fillStyle = '#4d5156';
ctx.font = '14px Arial, sans-serif';
const srDesc = "Discover comprehensive details about " + topic + ". This simulated search result provides context matching the web search interface format, emphasizing visual accuracy." + (i % 2 === 0 ? " Find expert tips." : " Gather critical insights.");
wrapText(ctx, srDesc, 160, resY + 68, 600, 20);
resY += 130;
}
// 4. Draw Knowledge Panel & Target Image (Right Side)
let srcX = 0, srcY = 0, srcW = originalImg.width, srcH = originalImg.height;
const drawW = 320;
let drawH = drawW * (srcH / srcW);
// Apply specific image scaling logic based on aspect ratio ('object-fit: cover' behavior)
if (drawH > 350) {
drawH = 350;
srcW = originalImg.width;
srcH = originalImg.width * (drawH / drawW);
srcX = 0;
srcY = (originalImg.height - srcH) / 2;
} else if (drawH < 150) {
drawH = 150;
srcH = originalImg.height;
srcW = originalImg.height * (drawW / drawH);
srcY = 0;
srcX = (originalImg.width - srcW) / 2;
}
const kpHeight = drawH + 180;
// Knowledge Panel Outer Card
ctx.fillStyle = '#ffffff';
ctx.strokeStyle = '#dfe1e5';
drawRoundRect(ctx, 840, 210, drawW, kpHeight, 10, true, true);
// Draw and clip the original provided image seamlessly into the card top
ctx.save();
drawRoundRect(ctx, 840, 210, drawW, drawH, {tl: 10, tr: 10, br: 0, bl: 0}, false, false);
ctx.clip();
ctx.drawImage(originalImg, srcX, srcY, srcW, srcH, 840, 210, drawW, drawH);
ctx.restore();
// Divider under the target image
ctx.beginPath();
ctx.moveTo(840, 210 + drawH);
ctx.lineTo(840 + drawW, 210 + drawH);
ctx.strokeStyle = '#dfe1e5';
ctx.stroke();
// Prominent Knowledge Panel Card Title
ctx.fillStyle = '#202124';
ctx.font = 'normal 24px Arial, sans-serif';
const kpTextY = 210 + drawH + 36;
ctx.fillText(topic, 856, kpTextY, 288);
// Grayed Card Subtitle
ctx.fillStyle = '#70757a';
ctx.font = '14px Arial, sans-serif';
ctx.fillText("Featured Topic Entity", 856, kpTextY + 22);
// Explanatory Panel Description
ctx.fillStyle = '#4d5156';
ctx.font = '14px Arial, sans-serif';
const desc = "A comprehensive visual overview of the designated target image wrapped nicely into a simulated knowledge panel on a desktop search interface layout.";
wrapText(ctx, desc, 856, kpTextY + 54, 288, 20);
return canvas;
}
Apply Changes