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
eff24ea6
Commit
eff24ea6
authored
Nov 24, 2023
by
comfyanonymous
Browse files
Add a node to save animated PNG files. These work in ffpmeg unlike webp.
parent
3e5ea74a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
+56
-0
comfy_extras/nodes_images.py
comfy_extras/nodes_images.py
+56
-0
No files found.
comfy_extras/nodes_images.py
View file @
eff24ea6
...
@@ -3,6 +3,8 @@ import folder_paths
...
@@ -3,6 +3,8 @@ import folder_paths
from
comfy.cli_args
import
args
from
comfy.cli_args
import
args
from
PIL
import
Image
from
PIL
import
Image
from
PIL.PngImagePlugin
import
PngInfo
import
numpy
as
np
import
numpy
as
np
import
json
import
json
import
os
import
os
...
@@ -112,8 +114,62 @@ class SaveAnimatedWEBP:
...
@@ -112,8 +114,62 @@ class SaveAnimatedWEBP:
animated
=
num_frames
!=
1
animated
=
num_frames
!=
1
return
{
"ui"
:
{
"images"
:
results
,
"animated"
:
(
animated
,)
}
}
return
{
"ui"
:
{
"images"
:
results
,
"animated"
:
(
animated
,)
}
}
class
SaveAnimatedPNG
:
def
__init__
(
self
):
self
.
output_dir
=
folder_paths
.
get_output_directory
()
self
.
type
=
"output"
self
.
prefix_append
=
""
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"images"
:
(
"IMAGE"
,
),
"filename_prefix"
:
(
"STRING"
,
{
"default"
:
"ComfyUI"
}),
"fps"
:
(
"FLOAT"
,
{
"default"
:
12.0
,
"min"
:
0.01
,
"max"
:
1000.0
,
"step"
:
0.01
}),
"compress_level"
:
(
"INT"
,
{
"default"
:
4
,
"min"
:
0
,
"max"
:
9
})
},
"hidden"
:
{
"prompt"
:
"PROMPT"
,
"extra_pnginfo"
:
"EXTRA_PNGINFO"
},
}
RETURN_TYPES
=
()
FUNCTION
=
"save_images"
OUTPUT_NODE
=
True
CATEGORY
=
"_for_testing"
def
save_images
(
self
,
images
,
fps
,
compress_level
,
filename_prefix
=
"ComfyUI"
,
prompt
=
None
,
extra_pnginfo
=
None
):
filename_prefix
+=
self
.
prefix_append
full_output_folder
,
filename
,
counter
,
subfolder
,
filename_prefix
=
folder_paths
.
get_save_image_path
(
filename_prefix
,
self
.
output_dir
,
images
[
0
].
shape
[
1
],
images
[
0
].
shape
[
0
])
results
=
list
()
pil_images
=
[]
for
image
in
images
:
i
=
255.
*
image
.
cpu
().
numpy
()
img
=
Image
.
fromarray
(
np
.
clip
(
i
,
0
,
255
).
astype
(
np
.
uint8
))
pil_images
.
append
(
img
)
metadata
=
None
if
not
args
.
disable_metadata
:
metadata
=
PngInfo
()
if
prompt
is
not
None
:
metadata
.
add_text
(
"prompt"
,
json
.
dumps
(
prompt
))
if
extra_pnginfo
is
not
None
:
for
x
in
extra_pnginfo
:
metadata
.
add_text
(
x
,
json
.
dumps
(
extra_pnginfo
[
x
]))
file
=
f
"
{
filename
}
_
{
counter
:
05
}
_.png"
pil_images
[
0
].
save
(
os
.
path
.
join
(
full_output_folder
,
file
),
pnginfo
=
metadata
,
compress_level
=
compress_level
,
save_all
=
True
,
duration
=
int
(
1000.0
/
fps
),
append_images
=
pil_images
[
1
:])
results
.
append
({
"filename"
:
file
,
"subfolder"
:
subfolder
,
"type"
:
self
.
type
})
return
{
"ui"
:
{
"images"
:
results
,
"animated"
:
(
True
,)}
}
NODE_CLASS_MAPPINGS
=
{
NODE_CLASS_MAPPINGS
=
{
"ImageCrop"
:
ImageCrop
,
"ImageCrop"
:
ImageCrop
,
"RepeatImageBatch"
:
RepeatImageBatch
,
"RepeatImageBatch"
:
RepeatImageBatch
,
"SaveAnimatedWEBP"
:
SaveAnimatedWEBP
,
"SaveAnimatedWEBP"
:
SaveAnimatedWEBP
,
"SaveAnimatedPNG"
:
SaveAnimatedPNG
,
}
}
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