You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, websiteAddress = "https://example.com") {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
let imgW = originalImg.width;
let imgH = originalImg.height;
// Enforce a minimum width so the browser UI remains usable and aesthetically pleasing
if (imgW < 500) {
const ratio = 500 / imgW;
imgW = 500;
imgH = originalImg.height * ratio;
}
// Determine scaling based on image size to maintain UI proportions
const scale = Math.max(1, imgW / 1000);
const headerH = 50 * scale;
const padding = 40 * scale;
canvas.width = imgW + padding * 2;
canvas.height = imgH + headerH + padding * 2;
// Helper to draw rounded rectangle backwards compatible with older canvas versions
function roundRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
// Add a shadow to create a nice floating window effect
ctx.shadowColor = 'rgba(0, 0, 0, 0.25)';
ctx.shadowBlur = 20 * scale;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 10 * scale;
// Draw the base white backboard for the browser window
ctx.fillStyle = '#ffffff';
roundRect(ctx, padding, padding, imgW, imgH + headerH, 10 * scale);
ctx.fill();
// Reset shadow so it doesn't apply to inner elements
ctx.shadowColor = 'transparent';
// Clip all subsequent drawing inside the rounded window corners
ctx.save();
roundRect(ctx, padding, padding, imgW, imgH + headerH, 10 * scale);
ctx.clip();
// --- Draw the browser header (Top bar) ---
ctx.fillStyle = '#f6f6f6';
ctx.fillRect(padding, padding, imgW, headerH);
// Subtle bottom border line for the header
ctx.fillStyle = '#dcdcdc';
ctx.fillRect(padding, padding + headerH - 1 * scale, imgW, 1 * scale);
// --- Draw Mac-style window controls (Red, Yellow, Green dots) ---
const btnRadius = 6 * scale;
const btnY = padding + headerH / 2;
const colors = ['#ff5f56', '#ffbd2e', '#27c93f']; // Traffic light colors
colors.forEach((color, i) => {
ctx.beginPath();
ctx.arc(padding + (20 + i * 20) * scale, btnY, btnRadius, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
});
// --- Draw the Address input box ---
const addrX = 90 * scale;
const addrW = imgW - 110 * scale;
const addrH = 28 * scale;
const addrY = padding + (headerH - addrH) / 2;
ctx.fillStyle = '#ffffff';
ctx.strokeStyle = '#e0e0e0';
ctx.lineWidth = 1 * scale;
roundRect(ctx, padding + addrX, addrY, addrW, addrH, 6 * scale);
ctx.fill();
ctx.stroke();
// --- Draw the Address/Identifier Text ---
ctx.fillStyle = '#444444';
const fontSize = 13 * scale;
ctx.font = `${fontSize}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
// Prefix a lock symbol to mimic secure connections
const displayAddress = "🔒 " + websiteAddress;
const textX = padding + addrX + addrW / 2;
const textY = padding + headerH / 2;
// Use maxWidth parameter to automatically scale text down if it's too long
ctx.fillText(displayAddress, textX, textY, addrW - 20 * scale);
// --- Draw the Original Image ---
ctx.imageSmoothingEnabled = true;
ctx.imageSmoothingQuality = 'high';
ctx.drawImage(originalImg, padding, padding + headerH, imgW, imgH);
ctx.restore();
return canvas;
}
Apply Changes