Add gallery argument to /imagine command (#5168) * Add gallery argument to /imagine to skip character gallery save Adds a `gallery` named argument (default: true) to the /imagine slash command. When `gallery=false`, the generated image is saved to the generic images directory instead of the character-specific gallery folder, while still returning a usable image URL. This is useful for extensions that manage their own image display (e.g. inline in chat messages) and don't need gallery copies. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Can't assign to a constant * Update help string to clarify image saving behavior in generation requests * Fix file name template if no char name provided --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

3a952293b48f2803d6973ae08cf7b4c5a1b33861

bal-spec <186531371+bal-spec@users.noreply.github.com>

Signed
1 files changed, +10 -3Ignore whitespace
public/scripts/extensions/stable-diffusion/index.js+10 -3
@@ -2952,7 +2952,7 @@ async function generatePicture(initiator, args, trigger, message, callback) {
2952 const quietPrompt = getQuietPrompt(generationType, trigger);2952 const quietPrompt = getQuietPrompt(generationType, trigger);
2953 const context = getContext();2953 const context = getContext();
29542954
2955 const characterName = context.groupId2955 let characterName = context.groupId
2956 ? context.groups[Object.keys(context.groups).filter(x => context.groups[x].id === context.groupId)[0]]?.id?.toString()2956 ? context.groups[Object.keys(context.groups).filter(x => context.groups[x].id === context.groupId)[0]]?.id?.toString()
2957 : context.characters[context.characterId]?.name;2957 : context.characters[context.characterId]?.name;
29582958
@@ -2974,6 +2974,10 @@ async function generatePicture(initiator, args, trigger, message, callback) {
2974 callback = () => { };2974 callback = () => { };
2975 }2975 }
29762976
2977 if (isFalseBoolean(args?.gallery)) {
2978 characterName = '';
2979 }
2980
2977 const dimensions = setTypeSpecificDimensions(generationType);2981 const dimensions = setTypeSpecificDimensions(generationType);
2978 const abortController = new AbortController();2982 const abortController = new AbortController();
2979 const stopButton = document.getElementById('sd_stop_gen');2983 const stopButton = document.getElementById('sd_stop_gen');
@@ -3366,7 +3370,7 @@ async function sendGenerationRequest(generationType, prompt, additionalNegativeP
3366 return;3370 return;
3367 }3371 }
33683372
3369 const filename = `${characterName}_${humanizedDateTime()}`;3373 const filename = characterName ? `${characterName}_${humanizedDateTime()}` : humanizedDateTime();
3370 const base64Image = await saveBase64AsFile(result.data, characterName, filename, result.format);3374 const base64Image = await saveBase64AsFile(result.data, characterName, filename, result.format);
3371 callback3375 callback
3372 ? await callback(prompt, base64Image, generationType, additionalNegativePrefix, initiator, prefixedPrompt, result.format)3376 ? await callback(prompt, base64Image, generationType, additionalNegativePrefix, initiator, prefixedPrompt, result.format)
@@ -5372,6 +5376,9 @@ jQuery(async () => {
5372 new SlashCommandNamedArgument(5376 new SlashCommandNamedArgument(
5373 'quiet', 'whether to post the generated image to chat', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',5377 'quiet', 'whether to post the generated image to chat', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
5374 ),5378 ),
5379 new SlashCommandNamedArgument(
5380 'gallery', 'whether to save the generated image to the character gallery', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true',
5381 ),
5375 SlashCommandNamedArgument.fromProps({5382 SlashCommandNamedArgument.fromProps({
5376 name: 'negative',5383 name: 'negative',
5377 description: 'negative prompt prefix',5384 description: 'negative prompt prefix',
@@ -5554,7 +5561,7 @@ jQuery(async () => {
5554 ],5561 ],
5555 helpString: `5562 helpString: `
5556 <div>5563 <div>
5557 Requests to generate an image and posts it to chat (unless <code>quiet=true</code> argument is specified).5564 Requests to generate an image and posts it to chat (unless <code>quiet=true</code> argument is specified). The image is saved to the character gallery by default; use <code>gallery=false</code> to save to the root of the user images directory.
5558 </div>5565 </div>
5559 <div>5566 <div>
5560 Supported arguments: <code>${Object.values(triggerWords).flat().join(', ')}</code>.5567 Supported arguments: <code>${Object.values(triggerWords).flat().join(', ')}</code>.