{"record":{"id":"bc9d089160940540","repo":"Comfy-Org/ComfyUI","slug":"image-width-must-be-at-least-min-width-px-got-w","errorCode":null,"errorMessage":"Image width must be at least {min_width}px, got {width}px","messagePattern":"Image width must be at least (.+?)px, got (.+?)px","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/util/validation_utils.py","lineNumber":27,"sourceCode":"    if len(image.shape) == 4:\n        return image.shape[1], image.shape[2]\n    elif len(image.shape) == 3:\n        return image.shape[0], image.shape[1]\n    else:\n        raise ValueError(\"Invalid image tensor shape.\")\n\n\ndef validate_image_dimensions(\n    image: torch.Tensor,\n    min_width: int | None = None,\n    max_width: int | None = None,\n    min_height: int | None = None,\n    max_height: int | None = None,\n):\n    height, width = get_image_dimensions(image)\n\n    if min_width is not None and width < min_width:\n        raise ValueError(f\"Image width must be at least {min_width}px, got {width}px\")\n    if max_width is not None and width > max_width:\n        raise ValueError(f\"Image width must be at most {max_width}px, got {width}px\")\n    if min_height is not None and height < min_height:\n        raise ValueError(f\"Image height must be at least {min_height}px, got {height}px\")\n    if max_height is not None and height > max_height:\n        raise ValueError(f\"Image height must be at most {max_height}px, got {height}px\")\n\n\ndef validate_image_aspect_ratio(\n    image: torch.Tensor,\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 = True,  # True -> (min, max); False -> [min, max]\n) -> float:\n    \"\"\"Validates that image aspect ratio is within min and max. If a bound is None, that side is not checked.\"\"\"\n    w, h = get_image_dimensions(image)\n    if w <= 0 or h <= 0:","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/util/validation_utils.py#L9-L45","documentation":"ValueError from validate_image_dimensions when the computed image width is below the node/API's minimum width. Height/width come from get_image_dimensions ([B,H,W,C] uses shape[1]=H, shape[2]=W; [H,W,C] uses shape[0]=H, shape[1]=W). This guard rejects images too small for the target API before any network call.","triggerScenarios":"Calling validate_image_dimensions(image, min_width=N) with width < N — e.g., a 512px-wide image passed to an API node whose model requires min_width=768 (typical for OpenAI/generation endpoints with minimum resolution requirements).","commonSituations":"Downscaled or heavily resized images falling under provider minimums; small crops; chaining a resize node with too-small dimensions before an API image node.","solutions":["Upscale or re-generate the image so width >= min_width shown in the message.","Fix upstream resize/crop nodes that shrank the image.","Choose a different API node/model with lower minimum resolution requirements."],"exampleFix":"# before\nvalidate_image_dimensions(image, min_width=1024)  # image is 512 wide\n# after\nimage = torch.nn.functional.interpolate(image.permute(0,3,1,2), scale_factor=2, mode='bilinear').permute(0,2,3,1)\nvalidate_image_dimensions(image, min_width=1024)","handlingStrategy":"validation","validationCode":"def check_min_width(image: torch.Tensor, min_width: int) -> bool:\n    w = image.shape[2] if image.dim() == 4 else image.shape[1]\n    return w >= min_width","typeGuard":null,"tryCatchPattern":"if not check_min_width(image, MIN_W):\n    raise ValueError(f\"image too small: need width >= {MIN_W}\")\nvalidate_image_dimensions(image, min_width=MIN_W)","preventionTips":["Read the node's documented minimum resolution before wiring inputs","Add a resize/upscale node before API image nodes"],"tags":["validation","image","dimensions"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}