Skip to content

Add "Scale To Side Length" Resolution Mode to Image Batch Tool#1359

Closed
GlenCarpenter wants to merge 6 commits intomcmonkeyprojects:masterfrom
GlenCarpenter:feat-add-batch-scaletoside
Closed

Add "Scale To Side Length" Resolution Mode to Image Batch Tool#1359
GlenCarpenter wants to merge 6 commits intomcmonkeyprojects:masterfrom
GlenCarpenter:feat-add-batch-scaletoside

Conversation

@GlenCarpenter
Copy link
Copy Markdown

@GlenCarpenter GlenCarpenter commented Apr 29, 2026

Add "Scale Input To Side Length" Resolution Mode to Image Batch Tool

This was requested in Discord.

Adds a new resolution option to the Image Batch Tool that scales based on a target side-length pixel budget while preserving aspect ratio, with separate controls for input and output when needed.

What's New

  • New resolution mode: Scale Input To Side Length
    • Added alongside existing modes: From Parameter, From Image, Scale To Model, Scale To Model Or Above
  • Resolution popover + dropdown wiring
    • Uses manual popover composition plus dropdown trigger behavior (makeGenericPopover + makeDropdownInput with getPopoverElemsFor behavior)
  • Side-length controls in UI
    • Use same side length for input and output checkbox
    • Input Side Length slider/number (64 to 4096, default 1024)
    • Output Side Length slider/number (64 to 4096, default 1024), shown only when the checkbox is off
    • Sliders use helper wiring via enableSlidersIn
    • Slider container max width is 512px
  • Backend support
    • input_side_length, output_side_length, and use_same_side_length flow through to batch generation
    • Resolution scaling uses Utilities.ResToModelFit for aspect-preserving target pixel count
    • EXIF auto-orient is applied before resolution math to prevent rotated phone photos from being scaled incorrectly

Changes

  • src/BuiltinExtensions/ImageBatchTool/Assets/image_batcher.js
    • Added Scale Input To Side Length mode
    • Added conditional side-length UI and visibility logic
    • Replaced manual slider sync listeners with makeSliderInput + enableSlidersIn
    • Added use_same_side_length behavior and separate input/output side-length controls
  • src/BuiltinExtensions/ImageBatchTool/ImageBatchToolExtension.cs
    • Added and consumed use_same_side_length, input_side_length, output_side_length
    • Added side-length-based resolution scaling path using Utilities.ResToModelFit
    • Added EXIF auto-orient handling before resize logic

@GlenCarpenter
Copy link
Copy Markdown
Author

I feel like I should explain the reasoning why this is desired -

For most image edit models (like Klein or Qwen Edit), you will get much better results if the input image matches the output resolution.

So when using this with the 'Use as image prompt' option, this will set the image prompt to the same size as the output.

@GlenCarpenter GlenCarpenter marked this pull request as draft April 29, 2026 21:19
@GlenCarpenter
Copy link
Copy Markdown
Author

Converting to draft as I see there was actually some additional functionality requested:

the same aspect ratio but the output would have the higher resolution (based on the side length and the aspect ratio).

example. image prompt image is 1216×832 and another is 832x1216. i set 1536 as side length and my output image will be 1824x1248, and the image with the other aspect ratio (portrait) will be 1248x1824

So I am thinking we can have two sliders:

  • Input side length
  • Output side length

This would then resize the inputs and then set the output side length accordingly.

GlenCarpenter and others added 3 commits April 30, 2026 12:02
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@GlenCarpenter GlenCarpenter marked this pull request as ready for review April 30, 2026 19:24
await socket.SendAndReportError($"ImageBatchRun request from {session.User.UserID}, for folder '{input_folder}'", "Image batch needs to supply the images to at least one parameter.", API.WebsocketTimeout);
return null;
}
// In case someone tries to leverage the websocket API directly, not possible from UI
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment shouldn't be here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

}
Image image = new(File.ReadAllBytes(file), MediaType.GetByExtension(file.AfterLast('.')));
ISImage imgData = image.ToIS;
// Check EXIF to make sure we have the correct orientation
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, comment should be here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Image image = new(File.ReadAllBytes(file), MediaType.GetByExtension(file.AfterLast('.')));
ISImage imgData = image.ToIS;
// Check EXIF to make sure we have the correct orientation
if (imgData.Metadata?.ExifProfile?.TryGetValue(ExifTag.Orientation, out IExifValue<ushort> orientationValue) ?? false)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems out of place to be in this PR

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some camera photos with EXIF orientation data show up as 16:9 instead of 9:16. It is really an edge case and I can remove this if it is out of scope.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd be a separate issue post to make, a separate PR, likely not focused into the Image Batch tool code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

(int scaledInputWidth, int scaledInputHeight) = Utilities.ResToModelFit(imgData.Width, imgData.Height, inputSideLength * inputSideLength, 16);
image = (Image)((ImageFile)image).Resize(scaledInputWidth, scaledInputHeight);
imgData = image.ToIS;
if (useSameSideLength)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this boolean and code around it make no sense

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was made with batch 'image prompts' in mind, which would follow a different flow than the batch 'input image'.

  1. Allow users to resize the input images while maintaining aspect ratio
  2. Allow users to set the output images resolution while maintaining aspect ratio

Initially I had only used option 1, which resized the input image and set the output to exact same resolution. When I looked at the actual request the user had made, they had asked for the option to set the output size as well.

I think it would be possible to batch as 'image prompts' and include a <refiner> in the prompt set to upscale and achieve more or less the same effect. That is a little more costly with time. The more I think about it I'm inclined to this this is a bit of an edge case and maybe we should just keep option 1.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per conversation I have removed 'output' scaling functionality as well as renamed 'input side length' to just 'side length'

+ makeSliderInput(null, 'ext_image_batcher_input_side_length', '', 'Input Side Length', '', 1024, 64, 4096, 64, 4096, 64, false, false, false)
+ `</div>`
+ `<span id="ext_image_batcher_output_side_length_wrap" style="display:none;width:100%;max-width:512px;">`
+ makeSliderInput(null, 'ext_image_batcher_output_side_length', '', 'Output Side Length', '', 1024, 64, 4096, 64, 4096, 64, false, false, false)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value makes no sense to have

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

GlenCarpenter and others added 2 commits May 1, 2026 13:04
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Comment thread AGENTS.md

The list of experienced maintainers currently approved for this experiment are:
- Alex Goodwin (mcmonkey)
- Glen Carpenter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This restriction was not a joke.

@mcmonkey4eva
Copy link
Copy Markdown
Member

Closed and blacklisted for intentional violation of contributor requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants