You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, style = "Corporate", companyName = "AI STUDIO") {
// Create a canvas to output the processed image
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = originalImg.width;
canvas.height = originalImg.height;
// Render the original image onto the canvas
ctx.drawImage(originalImg, 0, 0);
// "AI" deterministic processing: Analyze image pixels to generate a "founded year"
const imgData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
let rSum = 0, gSum = 0, bSum = 0, count = 0;
// Sample a maximum of roughly 1000 pixels to calculate the image's average color
const step = Math.max(4, Math.floor((imgData.length / 4) / 1000) * 4);
for (let i = 0; i < imgData.length; i += step) {
if (i + 2 < imgData.length) {
rSum += imgData[i];
gSum += imgData[i + 1];
bSum += imgData[i + 2];
count++;
}
}
const rAvg = Math.floor(rSum / count);
const gAvg = Math.floor(gSum / count);
const bAvg = Math.floor(bSum / count);
// Pseudo-AI logic: create a unique visual hash for the image mapped to a year between 1950 and 2049
const factor = (rAvg * 3 + gAvg * 5 + bAvg * 7 + canvas.width + canvas.height) % 100;
const year = 1950 + factor;
// Define stamp scale based on image dimensions
const fontSize = Math.max(16, Math.floor(Math.min(canvas.width, canvas.height) / 25));
const padding = fontSize;
const text1 = String(companyName).toUpperCase();
const text2 = `EST. ${year}`;
ctx.textBaseline = 'top';
ctx.textAlign = 'center';
let fontName, bgColor, textColor, borderColor, shadowColor, glow;
const safeStyle = String(style || "Corporate").toLowerCase();
// Configure the visuals according to requested style
switch (safeStyle) {
case 'retro':
fontName = '"Courier New", Courier, monospace';
bgColor = 'rgba(244, 237, 216, 0.85)';
textColor = '#3e2723';
borderColor = '#3e2723';
shadowColor = 'transparent';
glow = 0;
break;
case 'futuristic':
fontName = 'Impact, sans-serif';
bgColor = 'rgba(10, 10, 20, 0.7)';
textColor = '#00ffff';
borderColor = '#00ffff';
shadowColor = '#00ffff';
glow = 10;
break;
case 'corporate':
default:
fontName = 'Arial, sans-serif';
bgColor = 'rgba(255, 255, 255, 0.9)';
textColor = '#333333';
borderColor = '#333333';
shadowColor = 'rgba(0,0,0,0.3)';
glow = 6;
break;
}
ctx.font = `bold ${fontSize}px ${fontName}`;
// Calculate badge sizing
const text1Width = ctx.measureText(text1).width;
ctx.font = `bold ${fontSize * 0.8}px ${fontName}`;
const text2Width = ctx.measureText(text2).width;
// Reselect main font after measurement
ctx.font = `bold ${fontSize}px ${fontName}`;
const boxWidth = Math.max(text1Width, text2Width) + padding * 3;
const boxHeight = fontSize * 2 + padding * 2.5;
// Position the badge in the bottom right corner
const x = canvas.width - boxWidth - padding;
const y = canvas.height - boxHeight - padding;
// Define corner radius for 'corporate' style
const radius = safeStyle === 'corporate' ? fontSize / 2 : 0;
// Draw the Badge Background (Fill)
ctx.save();
if (safeStyle === 'corporate') {
ctx.shadowColor = shadowColor;
ctx.shadowBlur = glow;
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
}
ctx.fillStyle = bgColor;
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + boxWidth - radius, y);
if (radius > 0) ctx.quadraticCurveTo(x + boxWidth, y, x + boxWidth, y + radius);
ctx.lineTo(x + boxWidth, y + boxHeight - radius);
if (radius > 0) ctx.quadraticCurveTo(x + boxWidth, y + boxHeight, x + boxWidth - radius, y + boxHeight);
ctx.lineTo(x + radius, y + boxHeight);
if (radius > 0) ctx.quadraticCurveTo(x, y + boxHeight, x, y + boxHeight - radius);
ctx.lineTo(x, y + radius);
if (radius > 0) ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
ctx.fill();
ctx.restore();
// Draw the Badge Border (Stroke)
ctx.save();
if (safeStyle === 'futuristic') {
ctx.shadowColor = shadowColor;
ctx.shadowBlur = glow;
}
ctx.lineWidth = Math.max(2, fontSize / 12);
ctx.strokeStyle = borderColor;
if (safeStyle === 'retro') {
ctx.setLineDash([fontSize / 3, fontSize / 3]);
}
ctx.stroke();
ctx.restore();
// Draw the Text Inside Badge
ctx.save();
ctx.fillStyle = textColor;
if (safeStyle === 'futuristic') {
ctx.shadowColor = shadowColor;
ctx.shadowBlur = glow;
}
const textCenterX = x + boxWidth / 2;
ctx.fillText(text1, textCenterX, y + padding);
ctx.font = `bold ${fontSize * 0.8}px ${fontName}`;
ctx.fillText(text2, textCenterX, y + padding + fontSize * 1.2);
ctx.restore();
return canvas;
}
Apply Changes