mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-07 20:12:35 +08:00
Merge aadccd28ca into 021ba20719
This commit is contained in:
commit
79d3016be9
@ -644,9 +644,13 @@ class ResizeImagesByShorterEdgeNode(ImageProcessingNode):
|
|||||||
if w < h:
|
if w < h:
|
||||||
new_w = shorter_edge
|
new_w = shorter_edge
|
||||||
new_h = int(h * (shorter_edge / w))
|
new_h = int(h * (shorter_edge / w))
|
||||||
else:
|
elif h < w:
|
||||||
new_h = shorter_edge
|
new_h = shorter_edge
|
||||||
new_w = int(w * (shorter_edge / h))
|
new_w = int(w * (shorter_edge / h))
|
||||||
|
else:
|
||||||
|
# Square image: set both dimensions directly to avoid precision loss from float operations
|
||||||
|
new_w = shorter_edge
|
||||||
|
new_h = shorter_edge
|
||||||
img = img.resize((new_w, new_h), Image.Resampling.LANCZOS)
|
img = img.resize((new_w, new_h), Image.Resampling.LANCZOS)
|
||||||
return pil_to_tensor(img)
|
return pil_to_tensor(img)
|
||||||
|
|
||||||
@ -674,9 +678,13 @@ class ResizeImagesByLongerEdgeNode(ImageProcessingNode):
|
|||||||
if w > h:
|
if w > h:
|
||||||
new_w = longer_edge
|
new_w = longer_edge
|
||||||
new_h = int(h * (longer_edge / w))
|
new_h = int(h * (longer_edge / w))
|
||||||
else:
|
elif h > w:
|
||||||
new_h = longer_edge
|
new_h = longer_edge
|
||||||
new_w = int(w * (longer_edge / h))
|
new_w = int(w * (longer_edge / h))
|
||||||
|
else:
|
||||||
|
# Square image: set both dimensions directly to avoid precision loss from float operations
|
||||||
|
new_w = longer_edge
|
||||||
|
new_h = longer_edge
|
||||||
img = img.resize((new_w, new_h), Image.Resampling.LANCZOS)
|
img = img.resize((new_w, new_h), Image.Resampling.LANCZOS)
|
||||||
resized_images.append(pil_to_tensor(img))
|
resized_images.append(pil_to_tensor(img))
|
||||||
return torch.cat(resized_images, dim=0)
|
return torch.cat(resized_images, dim=0)
|
||||||
|
|||||||
@ -395,10 +395,15 @@ class ResizeAndPadImage(IO.ComfyNode):
|
|||||||
|
|
||||||
scale_w = target_width / orig_width
|
scale_w = target_width / orig_width
|
||||||
scale_h = target_height / orig_height
|
scale_h = target_height / orig_height
|
||||||
scale = min(scale_w, scale_h)
|
|
||||||
|
|
||||||
new_width = int(orig_width * scale)
|
# When aspect ratios match, scale directly to target to avoid precision loss from float multiplication
|
||||||
new_height = int(orig_height * scale)
|
if scale_w == scale_h:
|
||||||
|
new_width = target_width
|
||||||
|
new_height = target_height
|
||||||
|
else:
|
||||||
|
scale = min(scale_w, scale_h)
|
||||||
|
new_width = int(orig_width * scale)
|
||||||
|
new_height = int(orig_height * scale)
|
||||||
|
|
||||||
image_permuted = image.permute(0, 3, 1, 2)
|
image_permuted = image.permute(0, 3, 1, 2)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user