You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, keyName = "API Access Key", prefix = "sk_live_", keyLength = 32, creator = "API Key") {
// Validate parameters
let kLen = parseInt(keyLength, 10);
if (isNaN(kLen) || kLen < 8) kLen = 32;
// 1) Evaluate the deterministic hash of the original image pixels
const tempCanvas = document.createElement('canvas');
tempCanvas.width = originalImg.width || 1;
tempCanvas.height = originalImg.height || 1;
const tempCtx = tempCanvas.getContext('2d');
tempCtx.drawImage(originalImg, 0, 0);
let hashBase64 = "";
try {
const imgData = tempCtx.getImageData(0, 0, tempCanvas.width, tempCanvas.height).data;
let bytes = [];
// Sample up to ~512 pixels across the image to generate a reliable unique seed
const step = Math.max(4, Math.floor(imgData.length / 512) * 4);
for (let i = 0; i < imgData.length - 2; i += step) {
// Mix RGB channels into a single byte
let byteVal = (imgData[i] ^ imgData[i+1] ^ imgData[i+2]) & 255;
// Constrain to visible ASCII printable characters to safely encode
byteVal = 33 + (byteVal % 94);
bytes.push(byteVal);
}
let sampleString = "";
for (let b of bytes) {
sampleString += String.fromCharCode(b);
}
// Convert to base64 and strip non-alphanumeric chars
hashBase64 = btoa(sampleString).replace(/[^a-zA-Z0-9]/g, '');
} catch (e) {
// Fallback for CORS (cross-origin taint) blocked images
const pseudoRandomSeed = originalImg.width * originalImg.height + Date.now();
hashBase64 = btoa(pseudoRandomSeed.toString()).replace(/[^a-zA-Z0-9]/g, '');
}
// Extend the hash up to the requested key length
let generatedKeyBase = hashBase64;
while (generatedKeyBase.length < kLen) {
generatedKeyBase += btoa(generatedKeyBase).replace(/[^a-zA-Z0-9]/g, '');
}
// Add lightweight salt based on image dimensions
const salt = btoa(`${originalImg.width}x${originalImg.height}`).replace(/[^a-zA-Z0-9]/g, '');
generatedKeyBase = (salt + generatedKeyBase);
const finalKey = prefix + generatedKeyBase.substring(0, kLen);
// 2) Prepare the Main Output Canvas
const canvas = document.createElement('canvas');
// Enforce reasonable minimal bounds for UI rendering
const minWidth = 600;
const minHeight = 400;
const scale = Math.max(1, minWidth / originalImg.width, minHeight / originalImg.height);
const width = originalImg.width * scale;
const height = originalImg.height * scale;
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
// Draw the image scaled up heavily blurred as a smooth dynamic background
ctx.filter = 'blur(8px) brightness(0.5)';
ctx.drawImage(originalImg, 0, 0, width, height);
ctx.filter = 'none'; // reset filter
// Calculate dimensions for the API Key Card UI
const cardWidth = Math.min(width * 0.85, 550);
const cardHeight = Math.min(height * 0.5, 180);
const x = (width - cardWidth) / 2;
const y = (height - cardHeight) / 2;
const radius = 16;
// 3) Draw Glassmorphism Card Element
ctx.save();
// Drop shadow
ctx.shadowColor = 'rgba(0, 0, 0, 0.7)';
ctx.shadowBlur = 20;
ctx.shadowOffsetY = 10;
// Glass gradient background
const grad = ctx.createLinearGradient(x, y, x, y + cardHeight);
grad.addColorStop(0, 'rgba(30, 41, 59, 0.9)');
grad.addColorStop(1, 'rgba(15, 23, 42, 0.95)');
ctx.fillStyle = grad;
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + cardWidth - radius, y);
ctx.quadraticCurveTo(x + cardWidth, y, x + cardWidth, y + radius);
ctx.lineTo(x + cardWidth, y + cardHeight - radius);
ctx.quadraticCurveTo(x + cardWidth, y + cardHeight, x + cardWidth - radius, y + cardHeight);
ctx.lineTo(x + radius, y + cardHeight);
ctx.quadraticCurveTo(x, y + cardHeight, x, y + cardHeight - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
ctx.fill();
// Subtle shiny inner card border
ctx.lineWidth = 1.5;
ctx.strokeStyle = 'rgba(255, 255, 255, 0.15)';
ctx.stroke();
ctx.restore();
// 4) Render Typography
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
// API Key Name
const nameFontSize = Math.max(16, cardHeight * 0.18);
ctx.font = `bold ${nameFontSize}px sans-serif`;
ctx.fillStyle = '#94A3B8'; // Slate 400
ctx.fillText(keyName.toUpperCase(), width / 2, y + cardHeight * 0.28);
// Render Final Custom Generated Key
let keyFontSize = Math.max(14, cardHeight * 0.22);
ctx.font = `bold ${keyFontSize}px monospace`;
let textMetrics = ctx.measureText(finalKey);
// Scale text down strictly if it would overflow horizontally
while (textMetrics.width > cardWidth * 0.75 && keyFontSize > 10) {
keyFontSize -= 1;
ctx.font = `bold ${keyFontSize}px monospace`;
textMetrics = ctx.measureText(finalKey);
}
const keyYPos = y + cardHeight * 0.62;
ctx.fillStyle = '#4ADE80'; // Vivid Green
ctx.fillText(finalKey, width / 2, keyYPos);
// "Copy to clipboard" stylistic dummy icon
const iconSize = keyFontSize * 0.8;
const iconX = (width / 2) + (textMetrics.width / 2) + 15;
const iconY = keyYPos;
ctx.strokeStyle = '#4ADE80';
ctx.lineWidth = 1.5;
// Background sheet path
ctx.beginPath();
ctx.rect(iconX + 4, iconY - iconSize / 2 - 4, iconSize * 0.75, iconSize);
ctx.stroke();
// Foreground sheet path
ctx.fillStyle = '#0F172A';
ctx.beginPath();
ctx.rect(iconX, iconY - iconSize / 2, iconSize * 0.75, iconSize);
ctx.fill();
ctx.stroke();
// Contextual Creator Footer
ctx.font = `italic 12px sans-serif`;
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
ctx.fillText(`Tool Creator: ${creator}`, width / 2, y + cardHeight - 20);
// Outlying Tool Watermark
ctx.textAlign = 'right';
ctx.textBaseline = 'bottom';
ctx.font = 'bold 12px sans-serif';
ctx.fillStyle = 'rgba(255, 255, 255, 0.4)';
ctx.fillText("IMAGE API KEY GENERATOR", width - 20, height - 20);
return canvas;
}
Apply Changes