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
195d7aec
Commit
195d7aec
authored
Mar 12, 2023
by
m957ymj75urz
Browse files
can specify a subfolder in the SaveImage node
parent
6d6758e9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
10 deletions
+19
-10
nodes.py
nodes.py
+10
-6
server.py
server.py
+6
-3
web/scripts/app.js
web/scripts/app.js
+3
-1
No files found.
nodes.py
View file @
195d7aec
...
...
@@ -780,7 +780,8 @@ class SaveImage:
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"images"
:
(
"IMAGE"
,
),
"filename_prefix"
:
(
"STRING"
,
{
"default"
:
"ComfyUI"
})},
"filename_prefix"
:
(
"STRING"
,
{
"default"
:
"ComfyUI"
}),
"subfolder"
:
(
"STRING"
,
{})},
"hidden"
:
{
"prompt"
:
"PROMPT"
,
"extra_pnginfo"
:
"EXTRA_PNGINFO"
},
}
...
...
@@ -791,7 +792,7 @@ class SaveImage:
CATEGORY
=
"image"
def
save_images
(
self
,
images
,
filename_prefix
=
"ComfyUI"
,
prompt
=
None
,
extra_pnginfo
=
None
):
def
save_images
(
self
,
images
,
filename_prefix
=
"ComfyUI"
,
subfolder
=
None
,
prompt
=
None
,
extra_pnginfo
=
None
):
def
map_filename
(
filename
):
prefix_len
=
len
(
filename_prefix
)
prefix
=
filename
[:
prefix_len
+
1
]
...
...
@@ -800,12 +801,15 @@ class SaveImage:
except
:
digits
=
0
return
(
digits
,
prefix
)
outputDirectory
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"output"
,
subfolder
);
try
:
counter
=
max
(
filter
(
lambda
a
:
a
[
1
][:
-
1
]
==
filename_prefix
and
a
[
1
][
-
1
]
==
"_"
,
map
(
map_filename
,
os
.
listdir
(
self
.
output
_dir
))))[
0
]
+
1
counter
=
max
(
filter
(
lambda
a
:
a
[
1
][:
-
1
]
==
filename_prefix
and
a
[
1
][
-
1
]
==
"_"
,
map
(
map_filename
,
os
.
listdir
(
output
Directory
))))[
0
]
+
1
except
ValueError
:
counter
=
1
except
FileNotFoundError
:
os
.
mkdir
(
self
.
output
_dir
)
os
.
mkdir
(
output
Directory
)
counter
=
1
paths
=
list
()
...
...
@@ -819,8 +823,8 @@ class SaveImage:
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
)
img
.
save
(
os
.
path
.
join
(
output
Directory
,
file
),
pnginfo
=
metadata
,
optimize
=
True
)
paths
.
append
(
os
.
path
.
join
(
subfolder
,
file
)
)
counter
+=
1
return
{
"ui"
:
{
"images"
:
paths
}
}
...
...
server.py
View file @
195d7aec
...
...
@@ -109,15 +109,18 @@ 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"
in
request
.
rel_url
.
query
:
type
=
request
.
rel_url
.
query
.
get
(
"type"
,
"output"
)
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"
]
if
"subfolder"
in
request
.
rel_url
.
query
:
output_dir
=
os
.
path
.
join
(
output_dir
,
request
.
rel_url
.
query
[
"subfolder"
])
file
=
request
.
rel_url
.
query
[
"file"
]
file
=
os
.
path
.
basename
(
file
)
file
=
os
.
path
.
join
(
output_dir
,
file
)
if
os
.
path
.
isfile
(
file
):
...
...
web/scripts/app.js
View file @
195d7aec
...
...
@@ -110,7 +110,9 @@ class ComfyApp {
const
img
=
new
Image
();
img
.
onload
=
()
=>
r
(
img
);
img
.
onerror
=
()
=>
r
(
null
);
img
.
src
=
"
/view/
"
+
src
;
var
filename
=
src
.
replace
(
/^.*
[\\\/]
/
,
''
);
var
subfolder
=
src
.
replace
(
filename
,
''
);
img
.
src
=
"
/view?file=
"
+
filename
+
"
&subfolder=
"
+
subfolder
;
});
})
).
then
((
imgs
)
=>
{
...
...
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