mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +00:00
feat: add ImageCompare node (#7538)
## Summary add ImageCompare node, which is high demand among custom nodes, such as rgthree, we should support as core node Need BE change https://github.com/comfyanonymous/ComfyUI/pull/11343 ## Screenshots (if applicable) https://github.com/user-attachments/assets/a37bdcd0-de59-4bdd-bfc7-1adbe92f5298 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7538-feat-add-ImageCompare-node-2cb6d73d36508163a7d5f4807aece01a) by [Unito](https://www.unito.io)
This commit is contained in:
48
src/extensions/core/imageCompare.ts
Normal file
48
src/extensions/core/imageCompare.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { NodeExecutionOutput } from '@/schemas/apiSchema'
|
||||
import { api } from '@/scripts/api'
|
||||
import { app } from '@/scripts/app'
|
||||
import { useExtensionService } from '@/services/extensionService'
|
||||
|
||||
useExtensionService().registerExtension({
|
||||
name: 'Comfy.ImageCompare',
|
||||
|
||||
async nodeCreated(node) {
|
||||
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: NodeExecutionOutput) {
|
||||
onExecuted?.call(this, output)
|
||||
|
||||
const aImages = (output as Record<string, unknown>).a_images as
|
||||
| Record<string, string>[]
|
||||
| undefined
|
||||
const bImages = (output as Record<string, unknown>).b_images as
|
||||
| Record<string, string>[]
|
||||
| undefined
|
||||
const rand = app.getRandParam()
|
||||
|
||||
const beforeUrl =
|
||||
aImages && aImages.length > 0
|
||||
? api.apiURL(`/view?${new URLSearchParams(aImages[0])}${rand}`)
|
||||
: ''
|
||||
const afterUrl =
|
||||
bImages && bImages.length > 0
|
||||
? api.apiURL(`/view?${new URLSearchParams(bImages[0])}${rand}`)
|
||||
: ''
|
||||
|
||||
const widget = node.widgets?.find((w) => w.type === 'imagecompare')
|
||||
|
||||
if (widget) {
|
||||
widget.value = {
|
||||
before: beforeUrl,
|
||||
after: afterUrl
|
||||
}
|
||||
widget.callback?.(widget.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user