You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, theme = "Cyberpunk", artStyle = "Digital Concept Art") {
// Determine image dimensions and scaling
const w = originalImg.width || 800;
const h = originalImg.height || 600;
// Create main container dashboard
const container = document.createElement('div');
container.style.background = "#18181b"; // Dark zinc
container.style.color = "#ffffff";
container.style.fontFamily = "system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'";
container.style.display = "flex";
container.style.flexDirection = "column";
container.style.width = "100%";
container.style.maxWidth = "960px";
container.style.borderRadius = "12px";
container.style.overflow = "hidden";
container.style.boxShadow = "0 10px 40px rgba(0,0,0,0.6)";
container.style.margin = "0 auto";
// Header section
const header = document.createElement('div');
header.style.padding = "24px";
header.style.background = "linear-gradient(135deg, #4338ca 0%, #be185d 100%)";
const h2 = document.createElement('h2');
h2.innerText = "AI Image Idea Search & Generator";
h2.style.margin = "0";
h2.style.fontSize = "26px";
h2.style.color = "#ffffff";
h2.style.fontWeight = "800";
h2.style.letterSpacing = "0.5px";
const pDesc = document.createElement('p');
pDesc.innerText = "Extracting spatial concepts and generating creative AI prompts based on the visual input.";
pDesc.style.margin = "6px 0 0 0";
pDesc.style.opacity = "0.9";
pDesc.style.color = "#fdf2f8";
pDesc.style.fontSize = "15px";
header.appendChild(h2);
header.appendChild(pDesc);
container.appendChild(header);
// Body content layout
const bodyContent = document.createElement('div');
bodyContent.style.display = "flex";
bodyContent.style.flexWrap = "wrap";
bodyContent.style.padding = "24px";
bodyContent.style.gap = "24px";
container.appendChild(bodyContent);
// --- Left Pane (Visualizations) --- //
const leftPane = document.createElement('div');
leftPane.style.flex = "1.2";
leftPane.style.minWidth = "300px";
leftPane.style.display = "flex";
leftPane.style.flexDirection = "column";
leftPane.style.gap = "20px";
bodyContent.appendChild(leftPane);
// 1. Original Reference
const thumbWrap = document.createElement('div');
const tTitle = document.createElement('h3');
tTitle.innerText = "Original Reference";
tTitle.style.marginTop = "0";
tTitle.style.marginBottom = "10px";
tTitle.style.color = "#a5b4fc";
tTitle.style.fontSize = "17px";
tTitle.style.fontWeight = "600";
thumbWrap.appendChild(tTitle);
const thumb = document.createElement('canvas');
const tw = Math.min(400, w);
const th = h * (tw / w);
thumb.width = tw;
thumb.height = th;
thumb.getContext('2d').drawImage(originalImg, 0, 0, tw, th);
thumb.style.maxWidth = "100%";
thumb.style.borderRadius = "8px";
thumb.style.border = "1px solid #3f3f46";
thumb.style.boxShadow = "0 4px 12px rgba(0,0,0,0.3)";
thumbWrap.appendChild(thumb);
leftPane.appendChild(thumbWrap);
// Calculate Image Data & Palette efficiently
const pCanvas = document.createElement('canvas');
pCanvas.width = 100;
pCanvas.height = 100;
const pCtx = pCanvas.getContext('2d', { willReadFrequently: true });
pCtx.drawImage(originalImg, 0, 0, 100, 100);
const pData = pCtx.getImageData(0,0,100,100).data;
const colorMap = {};
let lumSum = 0;
for (let i = 0; i < pData.length; i += 4) {
const r = pData[i], g = pData[i+1], b = pData[i+2];
lumSum += 0.299 * r + 0.587 * g + 0.114 * b;
// Quantize colors to ~3 bits per channel for rough bucketing
const qR = Math.round(r / 32) * 32;
const qG = Math.round(g / 32) * 32;
const qB = Math.round(b / 32) * 32;
const key = `${qR},${qG},${qB}`;
colorMap[key] = (colorMap[key] || 0) + 1;
}
const avgLum = lumSum / 10000; // 100x100 resolution
const sortedColors = Object.entries(colorMap).sort((a, b) => b[1] - a[1]);
let palette = [];
for (let [key, count] of sortedColors) {
const [r, g, b] = key.split(',').map(Number);
let highlySimilar = false;
// Avoid adding near-duplicate colors to palette
for (let p of palette) {
if ((Math.abs(p.r - r) + Math.abs(p.g - g) + Math.abs(p.b - b)) < 60) {
highlySimilar = true;
break;
}
}
if (!highlySimilar) palette.push({r, g, b});
if (palette.length >= 5) break;
}
// Fill palette if not enough varied colors
while(palette.length < 5) palette.push(palette[0] || {r: 128, g: 128, b: 128});
// 2. Palette Render
const palWrap = document.createElement('div');
const pTitle = document.createElement('h3');
pTitle.innerText = "Dominant Concept Palette";
pTitle.style.margin = "0 0 10px 0";
pTitle.style.color = "#a5b4fc";
pTitle.style.fontSize = "17px";
pTitle.style.fontWeight = "600";
palWrap.appendChild(pTitle);
const paletteRow = document.createElement('div');
paletteRow.style.display = "flex";
paletteRow.style.height = "45px";
paletteRow.style.borderRadius = "8px";
paletteRow.style.overflow = "hidden";
paletteRow.style.border = "1px solid #3f3f46";
paletteRow.style.boxShadow = "0 4px 12px rgba(0,0,0,0.3)";
palette.forEach(p => {
const b = document.createElement('div');
b.style.flex = "1";
b.style.backgroundColor = `rgb(${p.r},${p.g},${p.b})`;
paletteRow.appendChild(b);
});
palWrap.appendChild(paletteRow);
leftPane.appendChild(palWrap);
// 3. Duotone Concept Visualization
let pDark = palette[0], pLight = palette[0];
let minLum = 999, maxLum = -1;
palette.forEach(p => {
const lumSq = (0.299*p.r + 0.587*p.g + 0.114*p.b);
if(lumSq < minLum) { minLum = lumSq; pDark = p; }
if(lumSq > maxLum) { maxLum = lumSq; pLight = p; }
});
// Ensure sufficient contrast for the duotone map
if (Math.abs(maxLum - minLum) < 40) {
pLight = {r: 255, g: 255, b: 255};
pDark = {r: 15, g: 15, b: 25};
}
const duoWrap = document.createElement('div');
const dTitle = document.createElement('h3');
dTitle.innerText = "AI Concept Vision (Duotone)";
dTitle.style.margin = "0 0 10px 0";
dTitle.style.color = "#a5b4fc";
dTitle.style.fontSize = "17px";
dTitle.style.fontWeight = "600";
duoWrap.appendChild(dTitle);
const dCanvas = document.createElement('canvas');
dCanvas.width = tw;
dCanvas.height = th;
const dCtx = dCanvas.getContext('2d');
dCtx.drawImage(originalImg, 0, 0, tw, th);
const dImgData = dCtx.getImageData(0,0,tw,th);
// Apply duotone filter mapping
for (let i = 0; i < dImgData.data.length; i += 4) {
const pxLum = (0.299 * dImgData.data[i] + 0.587 * dImgData.data[i+1] + 0.114 * dImgData.data[i+2]);
const t = pxLum / 255;
dImgData.data[i] = pDark.r + (pLight.r - pDark.r) * t;
dImgData.data[i+1] = pDark.g + (pLight.g - pDark.g) * t;
dImgData.data[i+2] = pDark.b + (pLight.b - pDark.b) * t;
}
dCtx.putImageData(dImgData, 0, 0);
dCanvas.style.maxWidth = "100%";
dCanvas.style.borderRadius = "8px";
dCanvas.style.border = "1px solid #3f3f46";
dCanvas.style.boxShadow = "0 4px 12px rgba(0,0,0,0.3)";
duoWrap.appendChild(dCanvas);
leftPane.appendChild(duoWrap);
// --- Right Pane (Data & Generated Ideas) --- //
const rightPane = document.createElement('div');
rightPane.style.flex = "1.6";
rightPane.style.minWidth = "300px";
rightPane.style.display = "flex";
rightPane.style.flexDirection = "column";
rightPane.style.gap = "20px";
rightPane.style.background = "rgba(255,255,255,0.02)";
rightPane.style.padding = "24px";
rightPane.style.borderRadius = "12px";
rightPane.style.border = "1px solid #3f3f46";
bodyContent.appendChild(rightPane);
// 1. Composition Analysis Results
const aTitle = document.createElement('h3');
aTitle.innerText = "Feature Analysis";
aTitle.style.color = "#f472b6";
aTitle.style.margin = "0";
aTitle.style.fontSize = "19px";
aTitle.style.fontWeight = "600";
rightPane.appendChild(aTitle);
const ratio = w / h;
let ratioText = "Square Format";
if (ratio > 1.25) ratioText = "Landscape Format";
if (ratio > 1.8) ratioText = "Ultrawide Panoramic";
if (ratio < 0.8) ratioText = "Portrait Format";
if (ratio < 0.5) ratioText = "Tall Vertical";
let lumText = "Balanced Cinematic Lighting";
if (avgLum > 170) lumText = "Bright & Ethereal";
else if (avgLum > 210) lumText = "High Key (Overexposed)";
else if (avgLum < 90) lumText = "Low Key & Moody";
else if (avgLum < 40) lumText = "Extremely Dark / Shadowy";
function getColorName(r, g, b) {
if (r > 210 && g > 210 && b > 210) return "stark white";
if (r < 40 && g < 40 && b < 40) return "deep black";
if (Math.abs(r-g) < 20 && Math.abs(r-b) < 20 && Math.abs(g-b) < 20) return "monochrome gray";
if (r > g+40 && r > b+40) return "crimson red";
if (g > r+40 && g > b+40) return "lush green";
if (b > r+40 && b > g+40) return "azure blue";
if (r > b+30 && g > b+30 && Math.abs(r-g) < 30) return "golden yellow";
if (r > g+30 && b > g+30 && Math.abs(r-b) < 30) return "magenta purple";
if (g > r+30 && b > r+30 && Math.abs(g-b) < 30) return "teal cyan";
return "complex mixed tone";
}
const domColor = getColorName(palette[0].r, palette[0].g, palette[0].b);
const secColor = getColorName(palette[1].r, palette[1].g, palette[1].b);
const grid = document.createElement('div');
grid.style.display = "grid";
grid.style.gridTemplateColumns = "repeat(auto-fit, minmax(130px, 1fr))";
grid.style.gap = "12px";
const mkStatBlock = (label, val) => {
const block = document.createElement('div');
block.style.background = "rgba(0,0,0,0.3)";
block.style.padding = "12px";
block.style.borderRadius = "8px";
block.style.border = "1px solid #3f3f46";
block.innerHTML = `<div style="color:#a1a1aa; font-size:11px; text-transform:uppercase; letter-spacing:1px; margin-bottom:4px;">${label}</div><strong style="fontSize:14px; color:#e4e4e7;">${val}</strong>`;
return block;
};
grid.appendChild(mkStatBlock("Aspect Ratio", ratioText));
grid.appendChild(mkStatBlock("Atmosphere", lumText));
rightPane.appendChild(grid);
// 2. Generated Prompts Area
const pHeaderContainer = document.createElement('div');
pHeaderContainer.style.marginTop = "15px";
pHeaderContainer.style.borderBottom = "1px solid #34d399";
pHeaderContainer.style.paddingBottom = "8px";
const prTitle = document.createElement('h3');
prTitle.innerText = "Generated AI Prompts";
prTitle.style.color = "#34d399";
prTitle.style.margin = "0 0 6px 0";
prTitle.style.fontSize = "19px";
prTitle.style.fontWeight = "600";
pHeaderContainer.appendChild(prTitle);
const prDesc = document.createElement('p');
prDesc.innerText = "Copy these concepts entirely into Midjourney, Stable Diffusion, or DALL-E to explore generated ideas natively.";
prDesc.style.margin = "0";
prDesc.style.fontSize = "13px";
prDesc.style.color = "#a1a1aa";
pHeaderContainer.appendChild(prDesc);
rightPane.appendChild(pHeaderContainer);
// Creating sophisticated Prompt combinations
const promptTexts = [
`A masterpiece ${artStyle} featuring a ${theme} concept. Dominant thematic hues of ${domColor}, exhibiting a ${lumText.toLowerCase()} atmosphere. High aesthetic execution, trending on ArtStation, ${ratioText.toLowerCase()} composition.`,
`In the style of ${theme}, utilizing a stark color palette centered heavily around ${secColor} and ${domColor}. Cinematic lighting, profoundly detailed, intricate geometries, realistic textures, designed strictly as ${artStyle}.`,
`Creative reimagining: ${ratioText.toLowerCase()} framework with ${lumText.toLowerCase()} shadowing aesthetics. Intensely styled as ${theme} meets formal ${artStyle}, emphasizing conceptual depth, beautiful lighting, 8k resolution concept sketch.`
];
const pList = document.createElement('div');
pList.style.display = "flex";
pList.style.flexDirection = "column";
pList.style.gap = "12px";
promptTexts.forEach((text, i) => {
const box = document.createElement('div');
box.style.background = "rgba(0,0,0,0.3)";
box.style.padding = "14px";
box.style.borderRadius = "8px";
box.style.borderLeft = "4px solid #34d399";
const num = document.createElement('div');
num.innerText = `Idea Prompt ` + (i+1);
num.style.fontSize = "12px";
num.style.color = "#34d399";
num.style.fontWeight = "700";
num.style.marginBottom = "6px";
num.style.textTransform = "uppercase";
num.style.letterSpacing = "0.5px";
const pText = document.createElement('div');
pText.innerText = text;
pText.style.fontSize = "15px";
pText.style.lineHeight = "1.5";
pText.style.color = "#f4f4f5";
pText.style.fontStyle = "italic";
box.appendChild(num);
box.appendChild(pText);
pList.appendChild(box);
});
rightPane.appendChild(pList);
// 3. Search Keywords Component
const kTitle = document.createElement('h3');
kTitle.innerText = "Suggested Search Keywords";
kTitle.style.color = "#fbbf24";
kTitle.style.margin = "10px 0 0 0";
kTitle.style.fontSize = "17px";
kTitle.style.fontWeight = "600";
rightPane.appendChild(kTitle);
const kBox = document.createElement('div');
kBox.style.padding = "14px";
kBox.style.background = "#09090b";
kBox.style.borderRadius = "8px";
kBox.style.fontFamily = "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace";
kBox.style.color = "#fbbf24";
kBox.style.fontSize = "14px";
kBox.style.lineHeight = "1.5";
kBox.style.wordBreak = "break-all";
kBox.style.border = "1px dashed #fbbf24";
// Clean and split keywords
const rawKeywords = [theme, artStyle, domColor, secColor, lumText.replace('&', 'and').toLowerCase(), "reference", "moodboard feature", "generative concept", ratioText.split(' ')[0]];
kBox.innerText = rawKeywords.map(k => k.trim()).filter(k => k.length > 0).join(", ");
rightPane.appendChild(kBox);
return container;
}
Apply Changes