Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions essentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,52 @@ def execute(self, image, width, height, keep_proportion, interpolation="nearest"
outputs = F.interpolate(outputs, size=(height, width), mode=interpolation)
outputs = pb(outputs)

return(outputs, outputs.shape[2], outputs.shape[1],)
class ImageResizeMygo:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
"width": ("INT", { "default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 8, }),
"height": ("INT", { "default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 8, }),
"interpolation": (["nearest", "bilinear", "bicubic", "area", "nearest-exact", "lanczos"],),
"keep_proportion": ("BOOLEAN", { "default": True }),
"circumscribe": ("BOOLEAN", { "default": True }),
}
}

RETURN_TYPES = ("IMAGE", "INT", "INT",)
RETURN_NAMES = ("IMAGE", "width", "height",)
FUNCTION = "execute"
CATEGORY = "essentials"

def execute(self, image, width, height, keep_proportion, interpolation="nearest", circumscribe = True):
if keep_proportion is True:
_, oh, ow, _ = image.shape #batchsize, height, weight, channels
# print(image.shape)
width = ow if width == 0 else width
height = oh if height == 0 else height
if not circumscribe:
ratio = min(width / ow, height / oh)
else :
oriratio = ow/oh
newratio = width/height
ratio = height / oh if oriratio > newratio else width / ow
# if oriratio>newratio:
# ratio = height/oh
# else:
# ratio = width/ow
width = round(ow*ratio)
height = round(oh*ratio)

outputs = p(image)
if interpolation == "lanczos":
outputs = comfy.utils.lanczos(outputs, width, height)
else:
outputs = F.interpolate(outputs, size=(height, width), mode=interpolation)
outputs = pb(outputs)

return(outputs, outputs.shape[2], outputs.shape[1],)

class ImageFlip:
Expand Down Expand Up @@ -916,6 +962,7 @@ def execute(self, resolution):
"GetImageSize+": GetImageSize,

"ImageResize+": ImageResize,
"ImageResize++": ImageResizeMygo,
"ImageCrop+": ImageCrop,
"ImageFlip+": ImageFlip,

Expand Down Expand Up @@ -950,6 +997,7 @@ def execute(self, resolution):
NODE_DISPLAY_NAME_MAPPINGS = {
"GetImageSize+": "🔧 Get Image Size",
"ImageResize+": "🔧 Image Resize",
"ImageResize++": "🔧 Image Resize Mygo",
"ImageCrop+": "🔧 Image Crop",
"ImageFlip+": "🔧 Image Flip",

Expand Down