You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, query = "Thx 1983-2023", position = "center") {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const width = originalImg.width;
const height = originalImg.height;
canvas.width = width;
canvas.height = height;
// Draw the original image as the background
ctx.drawImage(originalImg, 0, 0);
// Calculate dimensions for the search bar overlay
let barWidth = width * 0.8;
if (barWidth > 800) barWidth = 800;
if (barWidth < 200) barWidth = width * 0.95;
let barHeight = Math.max(40, barWidth * 0.1);
if (barHeight > width * 0.15) barHeight = width * 0.15;
if (barHeight > height * 0.4) barHeight = height * 0.4;
const x = (width - barWidth) / 2;
let y;
// Determine vertical position
switch (position.toLowerCase()) {
case 'top':
y = Math.max(20, height * 0.1);
break;
case 'bottom':
y = Math.min(height - barHeight - 20, height * 0.9 - barHeight);
break;
case 'center':
default:
y = (height - barHeight) / 2;
break;
}
// Apply drop shadow for the search bar
ctx.shadowColor = 'rgba(0, 0, 0, 0.35)';
ctx.shadowBlur = barHeight * 0.3;
ctx.shadowOffsetY = barHeight * 0.15;
// Draw rounded rectangle (pill shape) for the search bar
ctx.beginPath();
const radius = barHeight / 2;
ctx.moveTo(x + radius, y);
ctx.lineTo(x + barWidth - radius, y);
ctx.quadraticCurveTo(x + barWidth, y, x + barWidth, y + radius);
ctx.lineTo(x + barWidth, y + barHeight - radius);
ctx.quadraticCurveTo(x + barWidth, y + barHeight, x + barWidth - radius, y + barHeight);
ctx.lineTo(x + radius, y + barHeight);
ctx.quadraticCurveTo(x, y + barHeight, x, y + barHeight - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
ctx.fillStyle = '#ffffff';
ctx.fill();
// Reset shadow to avoid affecting other drawings
ctx.shadowColor = 'transparent';
// Draw magnifying glass icon
ctx.strokeStyle = '#9aa0a6';
ctx.lineWidth = Math.max(2, barHeight * 0.06);
ctx.lineCap = 'round';
ctx.beginPath();
const cx = x + barHeight * 0.65;
const cy = y + barHeight * 0.45;
const r = barHeight * 0.15;
ctx.arc(cx, cy, r, 0, Math.PI * 2);
ctx.moveTo(cx + r * 0.707, cy + r * 0.707);
ctx.lineTo(cx + r * 2.0, cy + r * 2.0);
ctx.stroke();
// Draw search text
ctx.fillStyle = '#202124';
ctx.font = `${barHeight * 0.4}px Arial, sans-serif`;
ctx.textBaseline = 'middle';
// Prevent text from overflowing the search bar on the right side
ctx.save();
ctx.beginPath();
ctx.rect(x + barHeight * 1.3, y, barWidth - barHeight * 1.8, barHeight);
ctx.clip();
ctx.fillText(query, x + barHeight * 1.3, y + barHeight / 2);
ctx.restore();
return canvas;
}
Apply Changes