{"record":{"id":"06c4b12ee3479be4","repo":"Comfy-Org/ComfyUI","slug":"invalid-image-dimensions","errorCode":null,"errorMessage":"Invalid image dimensions","messagePattern":"Invalid image dimensions","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/util/validation_utils.py","lineNumber":70,"sourceCode":"def validate_images_aspect_ratio_closeness(\n    first_image: torch.Tensor,\n    second_image: torch.Tensor,\n    min_rel: float,  # e.g. 0.8\n    max_rel: float,  # e.g. 1.25\n    *,\n    strict: bool = False,  # True -> (min, max); False -> [min, max]\n) -> float:\n    \"\"\"\n    Validates that the two images' aspect ratios are 'close'.\n    The closeness factor is C = max(ar1, ar2) / min(ar1, ar2)  (C >= 1).\n    We require C <= limit, where limit = max(max_rel, 1.0 / min_rel).\n\n    Returns the computed closeness factor C.\n    \"\"\"\n    w1, h1 = get_image_dimensions(first_image)\n    w2, h2 = get_image_dimensions(second_image)\n    if min(w1, h1, w2, h2) <= 0:\n        raise ValueError(\"Invalid image dimensions\")\n    ar1 = w1 / h1\n    ar2 = w2 / h2\n    closeness = max(ar1, ar2) / min(ar1, ar2)\n    limit = max(max_rel, 1.0 / min_rel)\n    if (closeness >= limit) if strict else (closeness > limit):\n        raise ValueError(\n            f\"Aspect ratios must be close: ar1/ar2={ar1/ar2:.2g}, \"\n            f\"allowed range {min_rel}–{max_rel} (limit {limit:.2g}).\"\n        )\n    return closeness\n\n\ndef validate_aspect_ratio_string(\n    aspect_ratio: str,\n    min_ratio: tuple[float, float] | None = None,  # e.g. (1, 4)\n    max_ratio: tuple[float, float] | None = None,  # e.g. (4, 1)\n    *,\n    strict: bool = False,  # True -> (min, max); False -> [min, max]","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/util/validation_utils.py#L52-L88","documentation":"ValueError from validate_images_aspect_ratio_closeness when either of the two compared images has a non-positive dimension (min(w1,h1,w2,h2) <= 0). The function computes closeness C = max(ar1,ar2)/min(ar1,ar2), which is undefined for degenerate tensors, so it rejects them before dividing. Unlike validate_image_aspect_ratio, the message does not include the values.","triggerScenarios":"Calling validate_images_aspect_ratio_closeness(first, second, min_rel, max_rel) where first or second has a zero-sized dimension (bad slice, empty batch element).","commonSituations":"Comparing a generated image with a reference that was cropped to nothing; empty tensor from a failed loader; slicing bugs in custom pairing nodes.","solutions":["Verify both tensors have strictly positive H and W before pairing them.","Fix the crop/slice code that emptied one image.","Add a shape assertion in the calling node so failures point at the right tensor."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def pair_has_positive_dims(a: torch.Tensor, b: torch.Tensor) -> bool:\n    return all(min(t.shape[-2], t.shape[-3]) > 0 for t in (a, b))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate both tensors' shapes before pairing images","Log shapes when pairing fails to identify the degenerate input"],"tags":["validation","image","tensor","shape"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}