{"record":{"id":"b5878882f4fd5f88","repo":"Comfy-Org/ComfyUI","slug":"attempting-to-resize-to-a-0-x-0-image-resized-hei","errorCode":null,"errorMessage":"Attempting to resize to a 0 x 0 image. Resized height should be divisible by {side_mult}.","messagePattern":"Attempting to resize to a 0 x 0 image\\. Resized height should be divisible by (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/text_encoders/gemma4.py","lineNumber":1390,"sourceCode":"        return x\n\n\nclass Gemma4AudioProjector(Gemma4RMSNormProjector):\n    def __init__(self, config, dtype=None, device=None, ops=None):\n        super().__init__(config.get(\"audio_output_proj_dims\", 1536), config.get(\"text_hidden_size\", 2560), dtype=dtype, device=device, ops=ops)\n\n\n# Tokenizer and Wrappers\n\ndef _get_aspect_ratio_preserving_size(height, width, patch_size, max_patches, pooling_kernel_size):\n    target_px = max_patches * patch_size ** 2\n    factor = math.sqrt(target_px / (height * width))\n    side_mult = pooling_kernel_size * patch_size\n    target_height = math.floor(factor * height / side_mult) * side_mult\n    target_width = math.floor(factor * width / side_mult) * side_mult\n\n    if target_height == 0 and target_width == 0:\n        raise ValueError(f\"Attempting to resize to a 0 x 0 image. Resized height should be divisible by {side_mult}.\")\n\n    max_side_length = (max_patches // pooling_kernel_size ** 2) * side_mult\n    if target_height == 0:\n        target_height = side_mult\n        target_width = min(math.floor(width / height) * side_mult, max_side_length)\n    elif target_width == 0:\n        target_width = side_mult\n        target_height = min(math.floor(height / width) * side_mult, max_side_length)\n\n    if target_height * target_width > target_px:\n        raise ValueError(f\"Resizing [{height}x{width}] to [{target_height}x{target_width}] exceeds the patch budget.\")\n\n    return target_height, target_width\n\n\nclass Gemma4_Tokenizer():\n    tokenizer_json_data = None\n    prime_empty_thought = False","sourceCodeStart":1372,"sourceCodeEnd":1408,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/text_encoders/gemma4.py#L1372-L1408","documentation":"In comfy/text_encoders/gemma4.py, _get_aspect_ratio_preserving_size computes a resize that fits an image into a max_patches patch budget while keeping aspect ratio, rounding each side down to a multiple of side_mult = pooling_kernel_size * patch_size. If the source image is so small (or the budget so tight) that both rounded sides floor to 0, it raises this ValueError before attempting a 0x0 resize.","triggerScenarios":"Passing tiny images (e.g. 8x8 or 16x4 pixels) to the Gemma4 vision encoder; a max_patches/patch config that makes factor < side_mult / max(side); extreme aspect ratios where the short side rounds to zero pixels.","commonSituations":"Thumbnail or icon-sized images in a multimodal workflow; placeholder/blank images generated at minimal resolution; custom configs that shrink the patch budget; division behavior when height or width is very small relative to the other.","solutions":["Upscale small inputs to at least a few multiples of patch_size * pooling_kernel_size (e.g. >= 128px on the short side) before feeding the encoder.","Increase max_patches for the encoder config if it was lowered.","Skip/replace degenerate images (near-zero dimensions) rather than sending them through the vision path."],"exampleFix":"# before\nimage = Image.open('16x16_icon.png')  # both sides floor to 0 -> ValueError\n\n# after\nif min(image.size) < 128:\n    image = image.resize((max(image.size[0], 128), max(image.size[1], 128)))\nemb = tokenizer.encode_image(image)","handlingStrategy":"validation","validationCode":"side_mult = pooling_kernel_size * patch_size\nassert height >= side_mult and width >= side_mult, f'image {height}x{width} too small; each side must be >= {side_mult}'","typeGuard":"def is_gemma4_image_ok(h: int, w: int, patch: int, pool: int) -> bool:\n    side_mult = pool * patch\n    return h >= side_mult and w >= side_mult and h * w > 0","tryCatchPattern":null,"preventionTips":["Reject or upscale sub-100px images before the vision encoder.","Filter degenerate (near-zero dimension) images out of multimodal batches."],"tags":["text-encoder","gemma4","vision","image-resize","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}