You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, labelText = "Странная разновидность комара", boxColor = "#00ff00", confidence = 99.9) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = originalImg.width;
canvas.height = originalImg.height;
// Draw the original image onto the canvas
ctx.drawImage(originalImg, 0, 0);
// Setup coordinates for the "targeting" bounding box
const w = canvas.width;
const h = canvas.height;
// Bounding box dimensions (covering the central 60% of the image)
const bx = w * 0.2;
const by = h * 0.2;
const bw = w * 0.6;
const bh = h * 0.6;
// HUD / bounding box styles
ctx.strokeStyle = boxColor;
ctx.lineWidth = Math.max(2, w * 0.005);
// Bracket size for corners
const bracketSize = Math.min(bw, bh) * 0.15;
// Draw top-left bracket
ctx.beginPath();
ctx.moveTo(bx + bracketSize, by);
ctx.lineTo(bx, by);
ctx.lineTo(bx, by + bracketSize);
ctx.stroke();
// Draw top-right bracket
ctx.beginPath();
ctx.moveTo(bx + bw - bracketSize, by);
ctx.lineTo(bx + bw, by);
ctx.lineTo(bx + bw, by + bracketSize);
ctx.stroke();
// Draw bottom-left bracket
ctx.beginPath();
ctx.moveTo(bx + bracketSize, by + bh);
ctx.lineTo(bx, by + bh);
ctx.lineTo(bx, by + bh - bracketSize);
ctx.stroke();
// Draw bottom-right bracket
ctx.beginPath();
ctx.moveTo(bx + bw - bracketSize, by + bh);
ctx.lineTo(bx + bw, by + bh);
ctx.lineTo(bx + bw, by + bh - bracketSize);
ctx.stroke();
// Draw a small crosshair in the very center
const cx = w / 2;
const cy = h / 2;
const ch = Math.max(8, w * 0.015);
ctx.beginPath();
ctx.moveTo(cx - ch, cy);
ctx.lineTo(cx + ch, cy);
ctx.moveTo(cx, cy - ch);
ctx.lineTo(cx, cy + ch);
ctx.stroke();
// Prepare label text (e.g. "Странная разновидность комара: 99.9% match")
const displayLabel = `IDENTIFIED: ${labelText} (${confidence}%)`;
// Scale font size based on image width
const fontSize = Math.max(14, w * 0.025);
ctx.font = `bold ${fontSize}px Courier New, monospace`;
const textMetrics = ctx.measureText(displayLabel);
// Calculate text background padding and dimensions
const pad = Math.max(4, w * 0.01);
const bgW = textMetrics.width + pad * 2;
const bgH = fontSize + pad * 2.5;
const textX = bx;
let textY = by - bgH - pad;
// Ensure the label text doesn't flow off the top of the canvas
if (textY < 0) {
textY = by + pad;
}
// Draw semi-transparent background for text
ctx.fillStyle = boxColor;
ctx.globalAlpha = 0.25;
ctx.fillRect(textX, textY, bgW, bgH);
// Draw border for the text background
ctx.globalAlpha = 1.0;
ctx.strokeRect(textX, textY, bgW, bgH);
// Draw the main text
ctx.fillStyle = "#ffffff";
// Add text shadow to ensure visibility over bright images
ctx.shadowColor = '#000000';
ctx.shadowBlur = 4;
ctx.textBaseline = "top";
ctx.fillText(displayLabel, textX + pad, textY + pad);
// Reset shadow for the other HUD elements
ctx.shadowBlur = 0;
ctx.fillStyle = boxColor;
// Add some random "techy" targeting numbers underneath the box
const randLat = (Math.random() * 180 - 90).toFixed(4);
const randLon = (Math.random() * 360 - 180).toFixed(4);
const bottomText = `SYS OK | TGT_LOC: ${randLat}, ${randLon} | CONFIDENCE: HIGH`;
const smallFontSize = Math.max(10, w * 0.015);
ctx.font = `${smallFontSize}px Courier New, monospace`;
ctx.fillText(bottomText, bx, by + bh + pad);
// Minor decorative HUD blocks on the left
for (let i = 0; i < 5; i++) {
const blkWidth = w * 0.01;
const blkHeight = h * 0.02;
const blkY = by + (i * blkHeight * 1.5);
ctx.fillRect(bx - blkWidth - pad * 2, blkY, blkWidth, blkHeight);
}
return canvas;
}
Apply Changes