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>
Signed| @@ -2952,7 +2952,7 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2952 | 2952 | const quietPrompt = getQuietPrompt(generationType, trigger); |
| 2953 | 2953 | const context = getContext(); |
| 2954 | 2954 | |
| 2955 | 2955 | constlet characterName = context.groupId |
| 2956 | 2956 | ? context.groups[Object.keys(context.groups).filter(x => context.groups[x].id === context.groupId)[0]]?.id?.toString() |
| 2957 | 2957 | : context.characters[context.characterId]?.name; |
| 2958 | 2958 | |
| @@ -2974,6 +2974,10 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2974 | 2974 | callback = () => { }; |
| 2975 | 2975 | } |
| 2976 | 2976 | |
| 2977 | + if (isFalseBoolean(args?.gallery)) { | |
| 2978 | + characterName = ''; | |
| 2979 | + } | |
| 2980 | + | |
| 2977 | 2981 | const dimensions = setTypeSpecificDimensions(generationType); |
| 2978 | 2982 | const abortController = new AbortController(); |
| 2979 | 2983 | const stopButton = document.getElementById('sd_stop_gen'); |
| @@ -3366,7 +3370,7 @@ async function sendGenerationRequest(generationType, prompt, additionalNegativeP | ||
| 3366 | 3370 | return; |
| 3367 | 3371 | } |
| 3368 | 3372 | |
| 3369 | 3373 | const filename = characterName ? `${characterName}_${humanizedDateTime()}` : humanizedDateTime(); |
| 3370 | 3374 | const base64Image = await saveBase64AsFile(result.data, characterName, filename, result.format); |
| 3371 | 3375 | callback |
| 3372 | 3376 | ? await callback(prompt, base64Image, generationType, additionalNegativePrefix, initiator, prefixedPrompt, result.format) |
| @@ -5372,6 +5376,9 @@ jQuery(async () => { | ||
| 5372 | 5376 | new SlashCommandNamedArgument( |
| 5373 | 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 | 5382 | SlashCommandNamedArgument.fromProps({ |
| 5376 | 5383 | name: 'negative', |
| 5377 | 5384 | description: 'negative prompt prefix', |
| @@ -5554,7 +5561,7 @@ jQuery(async () => { | ||
| 5554 | 5561 | ], |
| 5555 | 5562 | helpString: ` |
| 5556 | 5563 | <div> |
| 5557 | 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 | 5565 | </div> |
| 5559 | 5566 | <div> |
| 5560 | 5567 | Supported arguments: <code>${Object.values(triggerWords).flat().join(', ')}</code>. |