ImageTransformKJ: fix preview node sizing & grid alignment - #683
Open
Nekodificador wants to merge 1 commit into
Open
ImageTransformKJ: fix preview node sizing & grid alignment#683Nekodificador wants to merge 1 commit into
Nekodificador wants to merge 1 commit into
Conversation
Stop the node from growing to the image on load, keep its height locked to the canvas (no crop / no padding) on resize, enforce a min width in both canvas and Vue node renderers, let the toolbar wrap, stop the focus-scroll hiding it, and align the grid overlay with the snap when extra padding is active. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Nekodificador
force-pushed
the
fix/image-transform-kj-ui
branch
from
June 28, 2026 00:02
2c30252 to
7e2ff70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey Kijai — a bundle of preview/UI fixes for the new Image Transform KJ node. Everything is in
web/js/image_transform.js, no Python touched. Several of these are generic patterns for any DOM-widget node that previews an image/canvas, so I've written them up in case they're useful for your other nodes too.What was wrong & how it's fixed
1. Node grew enormous when loading an image
On a fresh image, load called
fitNodeToImage(false)(exact resize → the node jumped to the image's pixel size). Now it keeps the current width and only fits the height to the image (fitNodeToImage(true, true)): the image scales to the node, the node never widens to the image.2. Resize cropped the preview or left empty padding
The DOM widget only reported
getMinHeight, so LiteGraph could give it more space (padding) or less (crop). Now the node height is locked to the canvas:getMinHeight == getMaxHeight == getHeight, plus acomputeSizeoverride and anonResizeheight-lock, so vertical drags always snap to the exact content height. It also shrinks when you switch to a smaller-ratio image instead of keeping the old margin.3. Min width didn't hold in Vue Nodes mode
Worth flagging the cross-renderer gotcha: the canvas renderer honours
computeSize()[0]as the min width, but Vue Nodes mode (useNodeResize) ignorescomputeSizeand reads the node element's inlinemin-width. So the min width is set both ways — viacomputeSizefor canvas, andel.style.minWidthon[data-node-id]for Vue.4. Toolbar clipped / vanished
flex-wrapso the toolbar flows to a 2nd row when narrow, and measure its height at runtime (ResizeObserver) instead of hardcoding it.mousedowndidcanvasEl.focus(), which auto-scrolled theoverflowwrapper and hid the toolbar; fixed withfocus({ preventScroll: true }).5. Preview clipped a few px at the bottom (ratio-dependent)
This one is a LiteGraph layout quirk — the canvas-mode DOM-widget row gets reserved a few px short of the canvas (rounding/timing), and it also shows up on other canvas-preview nodes. Two parts: the wrapper uses
overflow:visibleso the canvas is never clipped, and the reserved height is based on the canvas's realoffsetHeight(not a(width-30)*ratioestimate, whose rounding error scales with the aspect ratio and gave a different bottom margin per image). A small constant safety margin keeps the node border just past the canvas. The_syncLayoutResizeObserver re-locks the height once the canvas has rendered, so the first load looks the same as after a manual resize.6. Grid overlay misaligned from its own snap with extra padding
With pad-first extra padding (
pad_color/pad_edge), the snap (getCanvasScale) works in padded image pixels butgetGridParamsused unpadded dims, so the drawn cells took the image ratio (non-square) while the snap stayed square.getGridParamsnow adds the same pad-first padding, so cells stay square and aligned (keeps grid multiples correct for model-friendly crop sizes).Testing
Manually verified in ComfyUI (canvas and Vue Nodes renderers): fresh load, switching between portrait/landscape images, resizing from every corner, narrow-width toolbar wrap, drawing/moving bboxes, and grid + extra-padding alignment. Export output is unchanged — these are preview-only fixes.