From 459311bd7b628e33429da3dd0225b5806263c6d5 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 17 Mar 2026 19:22:31 -0500 Subject: [PATCH] Add background parameter to GenerateImageTool for transparency support The previous commit tried to enable transparency by allowing output_format: "png", but transparency in the OpenAI Image API is controlled by a separate "background" parameter, not the output format. Without it, the model was drawing checkerboard patterns to visually represent transparency instead of producing actual alpha channels. Add the background parameter ("transparent", "opaque", "auto") to the tool schema and pass it through to the API. Update the system prompt to instruct the AI to use both background: "transparent" and output_format: "png"/"webp" together. --- src/lib/system.ts | 3 ++- src/lib/tools/GenerateImageTool.ts | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/system.ts b/src/lib/system.ts index 085b41d7..cdd57844 100644 --- a/src/lib/system.ts +++ b/src/lib/system.ts @@ -192,7 +192,8 @@ Shakespeare supports AI-powered image generation. Users can configure an image m **Important Notes:** - Not all models support image generation. If users experience issues with image generation, they should try selecting a different image model in Settings > AI - The generate_image tool will only be available once a compatible image model is configured -- When generating images for projects, prefer "jpeg" or "webp" output formats with compression set between 70-90 for optimal file size. Use "png" format when transparency is needed (e.g., logos, icons, overlays). You must supply the output_format parameter when calling the generate_image tool. +- When generating images for projects, prefer "jpeg" or "webp" output formats with compression set between 70-90. You must supply these parameters when calling the generate_image tool to ensure optimal image quality and file size for web usage. +- **Transparency**: To generate images with transparent backgrounds (e.g., logos, icons, overlays), set \`background: "transparent"\` and use \`output_format: "png"\` or \`output_format: "webp"\`. Both parameters must be set together — \`output_format\` alone does not enable transparency. - **Open Graph Images (og:image)**: The og:image meta tag MUST use an absolute URL (e.g., \`https://example.com/og-image.jpg\`). Relative paths will not work for social media sharing. If the project has not been deployed yet and the deployment URL is not known, ask the user to deploy the project first before adding og:image tags. ## Working Around CORS Issues diff --git a/src/lib/tools/GenerateImageTool.ts b/src/lib/tools/GenerateImageTool.ts index 1f7902bd..f811923c 100644 --- a/src/lib/tools/GenerateImageTool.ts +++ b/src/lib/tools/GenerateImageTool.ts @@ -11,6 +11,7 @@ interface GenerateImageParams { output_format?: "png" | "jpeg" | "webp"; output_compression?: number; size?: "auto" | "1024x1024" | "1536x1024" | "1024x1536" | "256x256" | "512x512" | "1792x1024" | "1024x1792"; + background?: "transparent" | "opaque" | "auto"; } export type ImageGenerationMode = 'chat' | 'image'; @@ -23,6 +24,7 @@ export class GenerateImageTool implements Tool { output_format: z.enum(["png", "jpeg", "webp"]).optional().describe('Output format for the image (e.g., "png", "jpeg", "webp"). Support varies by model - leave blank if unsure'), output_compression: z.number().min(1).max(100).optional().describe('Compression quality for the image (0 to 100). Only applicable for "jpeg" and "webp" formats'), size: z.enum(["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"]).optional().describe('Size of the generated image (e.g., "1024x1024", "1536x1024"). Support varies by model - leave blank if unsure'), + background: z.enum(["transparent", "opaque", "auto"]).optional().describe('Background setting for the generated image. Use "transparent" for images that need transparency (e.g., logos, icons, overlays). Only supported with "png" or "webp" output formats'), }); constructor( @@ -36,7 +38,7 @@ export class GenerateImageTool implements Tool { ) {} async execute(args: GenerateImageParams): Promise { - const { prompt, output_format, output_compression, size } = args; + const { prompt, output_format, output_compression, size, background } = args; try { const client = createAIClient(this.provider, this.user, this.corsProxy); @@ -114,6 +116,7 @@ export class GenerateImageTool implements Tool { output_format, output_compression, size, + background, }); // Extract cost from response