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
15f8da28
Commit
15f8da28
authored
Jan 22, 2023
by
comfyanonymous
Browse files
Add a LoadImage node to load images for img2img.
parent
220afe33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
input/example.png
input/example.png
+0
-0
nodes.py
nodes.py
+23
-0
No files found.
input/example.png
0 → 100644
View file @
15f8da28
8.39 KB
nodes.py
View file @
15f8da28
...
@@ -58,6 +58,10 @@ class VAEEncode:
...
@@ -58,6 +58,10 @@ class VAEEncode:
FUNCTION
=
"encode"
FUNCTION
=
"encode"
def
encode
(
self
,
vae
,
pixels
):
def
encode
(
self
,
vae
,
pixels
):
x
=
(
pixels
.
shape
[
1
]
//
64
)
*
64
y
=
(
pixels
.
shape
[
2
]
//
64
)
*
64
if
pixels
.
shape
[
1
]
!=
x
or
pixels
.
shape
[
2
]
!=
y
:
pixels
=
pixels
[:,:
x
,:
y
,:]
return
(
vae
.
encode
(
pixels
),
)
return
(
vae
.
encode
(
pixels
),
)
class
CheckpointLoader
:
class
CheckpointLoader
:
...
@@ -205,6 +209,24 @@ class SaveImage:
...
@@ -205,6 +209,24 @@ class SaveImage:
img
.
save
(
f
"output/ComfyUI_
{
self
.
counter
:
05
}
_.png"
,
pnginfo
=
metadata
,
optimize
=
True
)
img
.
save
(
f
"output/ComfyUI_
{
self
.
counter
:
05
}
_.png"
,
pnginfo
=
metadata
,
optimize
=
True
)
self
.
counter
+=
1
self
.
counter
+=
1
class
LoadImage
:
input_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"input"
)
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"image"
:
(
os
.
listdir
(
s
.
input_dir
),
)},
}
RETURN_TYPES
=
(
"IMAGE"
,)
FUNCTION
=
"load_image"
def
load_image
(
self
,
image
):
image_path
=
os
.
path
.
join
(
self
.
input_dir
,
image
)
image
=
Image
.
open
(
image_path
).
convert
(
"RGB"
)
image
=
np
.
array
(
image
).
astype
(
np
.
float32
)
/
255.0
image
=
torch
.
from_numpy
(
image
[
None
])[
None
,]
return
image
NODE_CLASS_MAPPINGS
=
{
NODE_CLASS_MAPPINGS
=
{
"KSampler"
:
KSampler
,
"KSampler"
:
KSampler
,
...
@@ -216,6 +238,7 @@ NODE_CLASS_MAPPINGS = {
...
@@ -216,6 +238,7 @@ NODE_CLASS_MAPPINGS = {
"EmptyLatentImage"
:
EmptyLatentImage
,
"EmptyLatentImage"
:
EmptyLatentImage
,
"LatentUpscale"
:
LatentUpscale
,
"LatentUpscale"
:
LatentUpscale
,
"SaveImage"
:
SaveImage
,
"SaveImage"
:
SaveImage
,
"LoadImage"
:
LoadImage
}
}
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