add LoadImagesToBatch
This commit is contained in:
+4
-2
@@ -592,7 +592,7 @@ async def post_prompt_result(request):
|
||||
|
||||
# 导入节点
|
||||
from .nodes.PromptNode import GLIGENTextBoxApply_Advanced,EmbeddingPrompt,RandomPrompt,PromptSlide,PromptSimplification,PromptImage,JoinWithDelimiter
|
||||
from .nodes.ImageNode import CompositeImages,GridDisplayAndSave,GridInput,ImagesPrompt,SaveImageAndMetadata,SaveImageToLocal,SplitImage,GridOutput,GetImageSize_,MirroredImage,ImageColorTransfer,NoiseImage,TransparentImage,GradientImage,LoadImagesFromPath,LoadImagesFromURL,ResizeImage,TextImage,SvgImage,Image3D,ShowLayer,NewLayer,MergeLayers,CenterImage,AreaToMask,SmoothMask,SplitLongMask,ImageCropByAlpha,EnhanceImage,FaceToMask
|
||||
from .nodes.ImageNode import LoadImages_,CompositeImages,GridDisplayAndSave,GridInput,ImagesPrompt,SaveImageAndMetadata,SaveImageToLocal,SplitImage,GridOutput,GetImageSize_,MirroredImage,ImageColorTransfer,NoiseImage,TransparentImage,GradientImage,LoadImagesFromPath,LoadImagesFromURL,ResizeImage,TextImage,SvgImage,Image3D,ShowLayer,NewLayer,MergeLayers,CenterImage,AreaToMask,SmoothMask,SplitLongMask,ImageCropByAlpha,EnhanceImage,FaceToMask
|
||||
# from .nodes.Vae import VAELoader,VAEDecode
|
||||
from .nodes.ScreenShareNode import ScreenShareNode,FloatingVideo
|
||||
|
||||
@@ -626,6 +626,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ResizeImageMixlab":ResizeImage,
|
||||
"LoadImagesFromPath":LoadImagesFromPath,
|
||||
"LoadImagesFromURL":LoadImagesFromURL,
|
||||
"LoadImagesToBatch":LoadImages_,
|
||||
"TextImage":TextImage,
|
||||
"EnhanceImage":EnhanceImage,
|
||||
"SvgImage":SvgImage,
|
||||
@@ -740,7 +741,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"GridOutput":"Grid Output",
|
||||
"GetImageSize_":"Get Image Size",
|
||||
"VAEEncodeForInpaint_Frames":"VAE Encode For Inpaint Frames",
|
||||
"IncrementingListNode_":"Create Incrementing Number List"
|
||||
"IncrementingListNode_":"Create Incrementing Number List",
|
||||
"LoadImagesToBatch":"Load Images To Batch"
|
||||
}
|
||||
|
||||
# web ui的节点功能
|
||||
|
||||
+38
-1
@@ -8,12 +8,13 @@ import base64,os,random
|
||||
from io import BytesIO
|
||||
import folder_paths
|
||||
import json,io
|
||||
import comfy.utils
|
||||
from comfy.cli_args import args
|
||||
import cv2
|
||||
import string
|
||||
import math,glob
|
||||
from .Watcher import FolderWatcher
|
||||
|
||||
import hashlib
|
||||
|
||||
def composite_images(foreground, background, mask):
|
||||
width,height=foreground.size
|
||||
@@ -1131,6 +1132,42 @@ class EnhanceImage:
|
||||
|
||||
|
||||
|
||||
class LoadImages_:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
|
||||
return {"required":
|
||||
{"images": ("IMAGEBASE64",),
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "♾️Mixlab/Image"
|
||||
|
||||
INPUT_IS_LIST = False
|
||||
OUTPUT_IS_LIST = (False,)
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
FUNCTION = "load_image"
|
||||
def load_image(self, images):
|
||||
|
||||
# print(images)
|
||||
ims=[]
|
||||
for im in images['base64']:
|
||||
image = base64_to_image(im)
|
||||
image=image.convert('RGB')
|
||||
image=pil2tensor(image)
|
||||
ims.append(image)
|
||||
|
||||
image1 = ims[0]
|
||||
for image2 in ims[1:]:
|
||||
if image1.shape[1:] != image2.shape[1:]:
|
||||
image2 = comfy.utils.common_upscale(image2.movedim(-1, 1), image1.shape[2], image1.shape[1], "bilinear", "center").movedim(1, -1)
|
||||
image1 = torch.cat((image1, image2), dim=0)
|
||||
return (image1,)
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
("STRING",{"multiline": False,"default": "Hello World!"})
|
||||
对应 widgets.js 里:
|
||||
|
||||
@@ -158,7 +158,6 @@ class ColorInput:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
|
||||
"color":("TCOLOR",),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ app.registerExtension({
|
||||
async getCustomWidgets (app) {
|
||||
return {
|
||||
KEY (node, inputName, inputData, app) {
|
||||
console.log('##inputData', inputData)
|
||||
// console.log('##inputData', inputData)
|
||||
const widget = {
|
||||
type: inputData[0], // the type, CHEESE
|
||||
name: inputName, // the name, slice
|
||||
|
||||
@@ -618,9 +618,144 @@ app.registerExtension({
|
||||
|
||||
if (json && json[0]) {
|
||||
uploadWidget.select.style.display = 'block'
|
||||
createSelect(img, uploadWidget.select, json, prompt,text)
|
||||
createSelect(img, uploadWidget.select, json, prompt, text)
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const createInputImageForBatch = (base64, widget) => {
|
||||
let im = new Image()
|
||||
im.src = base64
|
||||
im.style = `width: 88px;`
|
||||
|
||||
im.addEventListener('click', e => {
|
||||
let newValue = []
|
||||
let items=widget.value?.base64||[];
|
||||
for (const v of items) {
|
||||
if (v != base64) newValue.push(v)
|
||||
}
|
||||
widget.value.base64=newValue;
|
||||
im.remove()
|
||||
})
|
||||
|
||||
return im
|
||||
}
|
||||
|
||||
app.registerExtension({
|
||||
name: 'Mixlab.Comfy.LoadImagesToBatch',
|
||||
async getCustomWidgets (app) {
|
||||
return {
|
||||
IMAGEBASE64 (node, inputName, inputData, app) {
|
||||
// console.log('##node', node)
|
||||
const widget = {
|
||||
value: {
|
||||
base64:[]
|
||||
}, // 不能[x,x,x]
|
||||
type: inputData[0], // the type
|
||||
name: inputName, // the name, slice
|
||||
size: [128, 32], // a default size
|
||||
draw (ctx, node, width, y) {},
|
||||
computeSize (...args) {
|
||||
return [128, 32] // a method to compute the current size of the widget
|
||||
},
|
||||
// serializeValue (nodeId, widgetIndex) {
|
||||
// return widget.value
|
||||
// },
|
||||
}
|
||||
// widget.something = something; // maybe adds stuff to it
|
||||
node.addCustomWidget(widget) // adds it to the node
|
||||
return widget // and returns it.
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async beforeRegisterNodeDef (nodeType, nodeData, app) {
|
||||
if (nodeType.comfyClass == 'LoadImagesToBatch') {
|
||||
const orig_nodeCreated = nodeType.prototype.onNodeCreated
|
||||
nodeType.prototype.onNodeCreated = function () {
|
||||
orig_nodeCreated?.apply(this, arguments)
|
||||
|
||||
let imagesWidget = this.widgets.filter(w => w.name == 'images')[0]
|
||||
|
||||
const widget = {
|
||||
type: 'div',
|
||||
name: 'image_base64',
|
||||
draw (ctx, node, widget_width, y, widget_height) {
|
||||
Object.assign(
|
||||
this.div.style,
|
||||
get_position_style(ctx, widget_width, 44, node.size[1])
|
||||
)
|
||||
},
|
||||
serialize:false
|
||||
}
|
||||
|
||||
widget.div = $el('div', {})
|
||||
|
||||
document.body.appendChild(widget.div)
|
||||
|
||||
let imagePreview = document.createElement('div')
|
||||
let imagesDiv = document.createElement('div') //显示图片
|
||||
imagesDiv.className = 'images_preview'
|
||||
imagesDiv.style = `width: calc(100% - 14px);
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
padding: 7px; justify-content: space-between;
|
||||
align-items: center;`
|
||||
let inputImage = document.createElement('input')
|
||||
inputImage.type = 'file'
|
||||
inputImage.addEventListener('change', e => {
|
||||
e.preventDefault()
|
||||
const file = e.target.files[0]
|
||||
const reader = new FileReader()
|
||||
reader.onload = async event => {
|
||||
const base64 = event.target.result
|
||||
// console.log(base64)
|
||||
if (!imagesWidget.value) imagesWidget.value = {base64:[]}
|
||||
imagesWidget.value.base64.push(base64)
|
||||
let im = createInputImageForBatch(base64,imagesWidget)
|
||||
imagesDiv.appendChild(im)
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
})
|
||||
|
||||
widget.div.appendChild(imagePreview)
|
||||
imagePreview.appendChild(imagesDiv)
|
||||
imagePreview.appendChild(inputImage)
|
||||
|
||||
this.addCustomWidget(widget)
|
||||
|
||||
// document.addEventListener('wheel', handleMouseWheel)
|
||||
|
||||
const onRemoved = this.onRemoved
|
||||
this.onRemoved = () => {
|
||||
inputImage.remove()
|
||||
widget.div.remove()
|
||||
try {
|
||||
// document.removeEventListener('wheel', handleMouseWheel)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
return onRemoved?.()
|
||||
}
|
||||
|
||||
this.serialize_widgets = true //需要保存参数
|
||||
}
|
||||
}
|
||||
},
|
||||
async loadedGraphNode (node, app) {
|
||||
if (node.type === 'LoadImagesToBatch') {
|
||||
// await sleep(0)
|
||||
let imagesWidget = node.widgets.filter(w => w.name === 'images')[0]
|
||||
let imagePreview = node.widgets.filter(w => w.name == 'image_base64')[0]
|
||||
|
||||
let pre = imagePreview.div.querySelector('.images_preview')
|
||||
for (const d of imagesWidget.value?.base64 || []) {
|
||||
let im = createInputImageForBatch(d,imagesWidget)
|
||||
pre.appendChild(im)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1159,7 +1159,7 @@ app.registerExtension({
|
||||
|
||||
let apps_opts = []
|
||||
for (const category in apps_map) {
|
||||
console.log('category', typeof category)
|
||||
// console.log('category', typeof category)
|
||||
if (category === '0') {
|
||||
apps_opts.push(
|
||||
...Array.from(apps_map[category], a => {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user