Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
0abe001e
"vscode:/vscode.git/clone" did not exist on "bcc81d31dbd07ead696a2635b83140891aa69712"
Commit
0abe001e
authored
Mar 20, 2023
by
comfyanonymous
Browse files
Merge branch 'save-images' of
https://github.com/m957ymj75urz/ComfyUI
parents
46b674c9
d1138e8b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
16 deletions
+39
-16
nodes.py
nodes.py
+26
-10
server.py
server.py
+10
-3
web/scripts/app.js
web/scripts/app.js
+2
-2
web/scripts/widgets.js
web/scripts/widgets.js
+1
-1
No files found.
nodes.py
View file @
0abe001e
...
...
@@ -718,7 +718,7 @@ class KSamplerAdvanced:
class
SaveImage
:
def
__init__
(
self
):
self
.
output_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"output"
)
self
.
url_suffix
=
"
"
self
.
type
=
"output
"
@
classmethod
def
INPUT_TYPES
(
s
):
...
...
@@ -737,25 +737,35 @@ class SaveImage:
def
save_images
(
self
,
images
,
filename_prefix
=
"ComfyUI"
,
prompt
=
None
,
extra_pnginfo
=
None
):
def
map_filename
(
filename
):
prefix_len
=
len
(
filename_prefix
)
prefix_len
=
len
(
os
.
path
.
basename
(
filename_prefix
)
)
prefix
=
filename
[:
prefix_len
+
1
]
try
:
digits
=
int
(
filename
[
prefix_len
+
1
:].
split
(
'_'
)[
0
])
except
:
digits
=
0
return
(
digits
,
prefix
)
subfolder
=
os
.
path
.
dirname
(
os
.
path
.
normpath
(
filename_prefix
))
filename
=
os
.
path
.
basename
(
os
.
path
.
normpath
(
filename_prefix
))
full_output_folder
=
os
.
path
.
join
(
self
.
output_dir
,
subfolder
)
if
os
.
path
.
commonpath
((
self
.
output_dir
,
os
.
path
.
realpath
(
full_output_folder
)))
!=
self
.
output_dir
:
print
(
"Saving image outside the output folder is not allowed."
)
return
try
:
counter
=
max
(
filter
(
lambda
a
:
a
[
1
][:
-
1
]
==
filename
_prefix
and
a
[
1
][
-
1
]
==
"_"
,
map
(
map_filename
,
os
.
listdir
(
self
.
output_
di
r
))))[
0
]
+
1
counter
=
max
(
filter
(
lambda
a
:
a
[
1
][:
-
1
]
==
filename
and
a
[
1
][
-
1
]
==
"_"
,
map
(
map_filename
,
os
.
listdir
(
full_
output_
folde
r
))))[
0
]
+
1
except
ValueError
:
counter
=
1
except
FileNotFoundError
:
os
.
m
kdir
(
self
.
output_dir
)
os
.
m
akedirs
(
full_output_folder
,
exist_ok
=
True
)
counter
=
1
if
not
os
.
path
.
exists
(
self
.
output_dir
):
os
.
makedirs
(
self
.
output_dir
)
path
s
=
list
()
result
s
=
list
()
for
image
in
images
:
i
=
255.
*
image
.
cpu
().
numpy
()
img
=
Image
.
fromarray
(
np
.
clip
(
i
,
0
,
255
).
astype
(
np
.
uint8
))
...
...
@@ -765,16 +775,22 @@ class SaveImage:
if
extra_pnginfo
is
not
None
:
for
x
in
extra_pnginfo
:
metadata
.
add_text
(
x
,
json
.
dumps
(
extra_pnginfo
[
x
]))
file
=
f
"
{
filename_prefix
}
_
{
counter
:
05
}
_.png"
img
.
save
(
os
.
path
.
join
(
self
.
output_dir
,
file
),
pnginfo
=
metadata
,
optimize
=
True
)
paths
.
append
(
file
+
self
.
url_suffix
)
file
=
f
"
{
filename
}
_
{
counter
:
05
}
_.png"
img
.
save
(
os
.
path
.
join
(
full_output_folder
,
file
),
pnginfo
=
metadata
,
optimize
=
True
)
results
.
append
({
"filename"
:
file
,
"subfolder"
:
subfolder
,
"type"
:
self
.
type
});
counter
+=
1
return
{
"ui"
:
{
"images"
:
paths
}
}
return
{
"ui"
:
{
"images"
:
results
}
}
class
PreviewImage
(
SaveImage
):
def
__init__
(
self
):
self
.
output_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"temp"
)
self
.
url_suffix
=
"?type=
temp"
self
.
type
=
"
temp"
@
classmethod
def
INPUT_TYPES
(
s
):
...
...
server.py
View file @
0abe001e
...
...
@@ -115,17 +115,24 @@ class PromptServer():
return
web
.
Response
(
status
=
400
)
@
routes
.
get
(
"/view
/{file}
"
)
@
routes
.
get
(
"/view"
)
async
def
view_image
(
request
):
if
"file"
in
request
.
match_info
:
if
"file
name
"
in
request
.
rel_url
.
query
:
type
=
request
.
rel_url
.
query
.
get
(
"type"
,
"output"
)
if
type
not
in
[
"output"
,
"input"
,
"temp"
]:
return
web
.
Response
(
status
=
400
)
output_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
type
)
file
=
request
.
match_info
[
"file"
]
if
"subfolder"
in
request
.
rel_url
.
query
:
full_output_dir
=
os
.
path
.
join
(
output_dir
,
request
.
rel_url
.
query
[
"subfolder"
])
if
os
.
path
.
commonpath
((
os
.
path
.
realpath
(
full_output_dir
),
output_dir
))
!=
output_dir
:
return
web
.
Response
(
status
=
403
)
output_dir
=
full_output_dir
file
=
request
.
rel_url
.
query
[
"filename"
]
file
=
os
.
path
.
basename
(
file
)
file
=
os
.
path
.
join
(
output_dir
,
file
)
if
os
.
path
.
isfile
(
file
):
return
web
.
FileResponse
(
file
)
...
...
web/scripts/app.js
View file @
0abe001e
...
...
@@ -110,7 +110,7 @@ class ComfyApp {
const
img
=
new
Image
();
img
.
onload
=
()
=>
r
(
img
);
img
.
onerror
=
()
=>
r
(
null
);
img
.
src
=
"
/view
/
"
+
src
;
img
.
src
=
"
/view
?
"
+
new
URLSearchParams
(
src
).
toString
()
;
});
})
).
then
((
imgs
)
=>
{
...
...
web/scripts/widgets.js
View file @
0abe001e
...
...
@@ -141,7 +141,7 @@ export const ComfyWidgets = {
node
.
imgs
=
[
img
];
app
.
graph
.
setDirtyCanvas
(
true
);
};
img
.
src
=
`/view
/
${
name
}
?
type=input`
;
img
.
src
=
`/view
?filename=
${
name
}
&
type=input`
;
}
// Add our own callback to the combo widget to render an image when it changes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment