Files
ComfyUI_frontend/src/extensions/core/imageCompare.ts
Comfy Org PR Bot a1af7e454c [backport core/1.41] Use preview downscaling in fewer places (#9682)
Backport of #9678 to `core/1.41`

Automatically created by backport workflow.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-9682-backport-core-1-41-Use-preview-downscaling-in-fewer-places-31e6d73d365081fb845ff568d2088070)
by [Unito](https://www.unito.io)

Co-authored-by: AustinMroz <austin@comfy.org>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Alexander Brown <drjkl@comfy.org>
2026-03-09 16:16:34 -07:00

48 lines
1.4 KiB
TypeScript

import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
import type { NodeOutputWith } from '@/schemas/apiSchema'
import { api } from '@/scripts/api'
import { app } from '@/scripts/app'
import { useExtensionService } from '@/services/extensionService'
type ImageCompareOutput = NodeOutputWith<{
a_images?: Record<string, string>[]
b_images?: Record<string, string>[]
}>
useExtensionService().registerExtension({
name: 'Comfy.ImageCompare',
async nodeCreated(node: LGraphNode) {
if (node.constructor.comfyClass !== 'ImageCompare') return
const [oldWidth, oldHeight] = node.size
node.setSize([Math.max(oldWidth, 400), Math.max(oldHeight, 350)])
const onExecuted = node.onExecuted
node.onExecuted = function (output: ImageCompareOutput) {
onExecuted?.call(this, output)
const { a_images: aImages, b_images: bImages } = output
const rand = app.getRandParam()
const toUrl = (record: Record<string, string>) => {
const params = new URLSearchParams(record)
return api.apiURL(`/view?${params}${rand}`)
}
const beforeImages =
aImages && aImages.length > 0 ? aImages.map(toUrl) : []
const afterImages =
bImages && bImages.length > 0 ? bImages.map(toUrl) : []
const widget = node.widgets?.find((w) => w.type === 'imagecompare')
if (widget) {
widget.value = { beforeImages, afterImages }
widget.callback?.(widget.value)
}
}
}
})