feat: allow reference images for AI layer edits and relax stylistic constraints to allow for realism
Build and Deploy / build-and-push (push) Successful in 2m9s

This commit is contained in:
AI Bot
2026-10-05 15:27:59 +05:30
parent f44a07b1a9
commit 527dfba535
3 changed files with 112 additions and 21 deletions
+27 -10
View File
@@ -649,7 +649,7 @@ CRITICAL INSTRUCTIONS:
// Edit Layer (Gemini Flash Image)
app.post('/api/sparkplug/edit-layer', authenticate, async (req, res) => {
const { prompt, imageBase64, mimeType } = req.body;
const { prompt, imageBase64, mimeType, referenceImageBase64, referenceMimeType } = req.body;
if (!prompt || !imageBase64) return res.status(400).json({ error: 'Missing prompt or image' });
try {
@@ -660,18 +660,35 @@ app.post('/api/sparkplug/edit-layer', authenticate, async (req, res) => {
const baseUrl = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image:generateContent';
const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, "");
const parts = [
{ text: `You are an expert texture editor. Edit the following image based on this prompt: "${prompt}".
CRITICAL INSTRUCTIONS:
1. Output MUST be an image with the exact same aspect ratio as the input layer image.
2. Do NOT change the layout, mapping, or boundaries of the texture.
3. You ARE encouraged to completely change the aesthetics, style, and realism of the texture as requested by the user, as long as the physical structure mapping remains intact.` },
{
inlineData: {
mimeType: mimeType || "image/png",
data: base64Data
}
}
];
if (referenceImageBase64) {
const refBase64Data = referenceImageBase64.replace(/^data:image\/\w+;base64,/, "");
parts.push({ text: "Use the following image purely as a stylistic reference for the edit:" });
parts.push({
inlineData: {
mimeType: referenceMimeType || "image/png",
data: refBase64Data
}
});
}
const payload = {
contents: [
{
parts: [
{ text: `You are an expert texture editor. Edit the following image based on this prompt: "${prompt}". \nCRITICAL INSTRUCTIONS:\n1. Output MUST be an image with the exact same aspect ratio as the input.\n2. Do NOT change the layout or mapping of the texture.\n3. Increase the resolution and quality of the visual elements as requested.` },
{
inlineData: {
mimeType: mimeType || "image/png",
data: base64Data
}
}
]
parts: parts
}
],
generationConfig: {