Skip to content

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

Open
GlenCarpenter wants to merge 4 commits intomcmonkeyprojects:masterfrom
GlenCarpenter:feat-add-batch-scaletoside
Open

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

Conversation

@GlenCarpenter
Copy link
Copy Markdown
Contributor

@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
Contributor 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
Contributor 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

}
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

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

(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

+ 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

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