Changed to upload to input dir
Fixed jpg Added dupe support Changed to use existing nodes
This commit is contained in:
parent
4a326a2548
commit
99abc0eb2e
8
nodes.py
8
nodes.py
|
@ -833,9 +833,6 @@ class LoadImage:
|
|||
m.update(f.read())
|
||||
return m.digest().hex()
|
||||
|
||||
class UploadImage(LoadImage):
|
||||
input_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "uploads")
|
||||
|
||||
class LoadImageMask:
|
||||
input_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input")
|
||||
@classmethod
|
||||
|
@ -871,9 +868,6 @@ class LoadImageMask:
|
|||
m.update(f.read())
|
||||
return m.digest().hex()
|
||||
|
||||
class UploadImageMask(LoadImageMask):
|
||||
input_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "uploads")
|
||||
|
||||
class ImageScale:
|
||||
upscale_methods = ["nearest-exact", "bilinear", "area"]
|
||||
crop_methods = ["disabled", "center"]
|
||||
|
@ -925,9 +919,7 @@ NODE_CLASS_MAPPINGS = {
|
|||
"LatentUpscale": LatentUpscale,
|
||||
"SaveImage": SaveImage,
|
||||
"LoadImage": LoadImage,
|
||||
"UploadImage": UploadImage,
|
||||
"LoadImageMask": LoadImageMask,
|
||||
"UploadImageMask": UploadImageMask,
|
||||
"ImageScale": ImageScale,
|
||||
"ImageInvert": ImageInvert,
|
||||
"ConditioningCombine": ConditioningCombine,
|
||||
|
|
16
server.py
16
server.py
|
@ -72,7 +72,7 @@ class PromptServer():
|
|||
|
||||
@routes.post("/upload/image")
|
||||
async def upload_image(request):
|
||||
upload_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "uploads")
|
||||
upload_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input")
|
||||
|
||||
if not os.path.exists(upload_dir):
|
||||
os.makedirs(upload_dir)
|
||||
|
@ -85,7 +85,15 @@ class PromptServer():
|
|||
if not filename:
|
||||
return web.Response(status=400)
|
||||
|
||||
with open(os.path.join(upload_dir, filename), "wb") as f:
|
||||
split = os.path.splitext(filename)
|
||||
i = 1
|
||||
while os.path.exists(os.path.join(upload_dir, filename)):
|
||||
filename = f"{split[0]} ({i}){split[1]}"
|
||||
i += 1
|
||||
|
||||
filepath = os.path.join(upload_dir, filename)
|
||||
|
||||
with open(filepath, "wb") as f:
|
||||
f.write(image.file.read())
|
||||
|
||||
return web.json_response({"name" : filename})
|
||||
|
@ -97,12 +105,12 @@ class PromptServer():
|
|||
async def view_image(request):
|
||||
if "file" in request.match_info:
|
||||
type = request.rel_url.query.get("type", "output")
|
||||
if type != "output" and type != "uploads":
|
||||
if type != "output" and type != "input":
|
||||
return web.Response(status=400)
|
||||
|
||||
output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), type)
|
||||
file = request.match_info["file"]
|
||||
file = os.path.splitext(os.path.basename(file))[0] + ".png"
|
||||
file = os.path.basename(file)
|
||||
file = os.path.join(output_dir, file)
|
||||
if os.path.isfile(file):
|
||||
return web.FileResponse(file)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { app } from "/scripts/app.js";
|
||||
|
||||
// Adds an upload button to the nodes
|
||||
|
||||
app.registerExtension({
|
||||
name: "Comfy.UploadImage",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "UploadImage" || nodeData.name === "UploadImageMask") {
|
||||
if (nodeData.name === "LoadImage" || nodeData.name === "LoadImageMask") {
|
||||
nodeData.input.required.upload = ["IMAGEUPLOAD"];
|
||||
}
|
||||
},
|
||||
|
|
|
@ -141,7 +141,7 @@ export const ComfyWidgets = {
|
|||
node.imgs = [img];
|
||||
app.graph.setDirtyCanvas(true);
|
||||
};
|
||||
img.src = `/view/${name}?type=uploads`;
|
||||
img.src = `/view/${name}?type=input`;
|
||||
}
|
||||
|
||||
// Add our own callback to the combo widget to render an image when it changes
|
||||
|
|
Loading…
Reference in New Issue