{"record":{"id":"28d876ba0cebb5ef","repo":"invoke-ai/InvokeAI","slug":"image-too-small-should-be-larger-than-256x256","errorCode":null,"errorMessage":"image too small, should be larger than 256x256","messagePattern":"image too small, should be larger than 256x256","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/image_util/imwatermark/vendor.py","lineNumber":84,"sourceCode":"            self.set_by_bits(content)\n        elif wmType == \"bytes\":\n            self.set_by_bytes(content)\n        elif wmType == \"b16\":\n            self.set_by_b16(content)\n        else:\n            raise NameError(\"%s is not supported\" % wmType)\n\n    def get_length(self):\n        return self._wmLen\n\n    # @classmethod\n    # def loadModel(cls):\n    #     RivaWatermark.loadModel()\n\n    def encode(self, cv2Image, method=\"dwtDct\", **configs):\n        (r, c, channels) = cv2Image.shape\n        if r * c < 256 * 256:\n            raise RuntimeError(\"image too small, should be larger than 256x256\")\n\n        if method == \"dwtDct\":\n            embed = EmbedMaxDct(self._watermarks, wmLen=self._wmLen, **configs)\n            return embed.encode(cv2Image)\n        # elif method == 'dwtDctSvd':\n        #     embed = EmbedDwtDctSvd(self._watermarks, wmLen=self._wmLen, **configs)\n        #     return embed.encode(cv2Image)\n        # elif method == 'rivaGan':\n        #     embed = RivaWatermark(self._watermarks, self._wmLen)\n        #     return embed.encode(cv2Image)\n        else:\n            raise NameError(\"%s is not supported\" % method)\n\n\nclass WatermarkDecoder(object):\n    def __init__(self, wm_type=\"bytes\", length=0):\n        self._wmType = wm_type\n        if wm_type == \"ipv4\":","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/image_util/imwatermark/vendor.py#L66-L102","documentation":"The vendored invisible-watermark encoder requires images with at least 256*256 pixels (r*c >= 65536) because the DCT-based embedding needs enough frequency blocks; smaller images raise RuntimeError.","triggerScenarios":"Calling encode() (via add_watermark) on images smaller than 256x256 in total pixel count — e.g. 128x512 thumbnails, 200x300 crops, or small icon outputs.","commonSituations":"Generating small preview images, watermarking downscaled thumbnails, resizing outputs below the threshold before watermarking.","solutions":["Upscale the image to at least 256x256 (total >= 65536 pixels) before encoding","Watermark the full-resolution image first, then downscale afterward","Skip watermarking for images below the size threshold with a graceful fallback"],"exampleFix":"// before\nencoder.encode(small_img, \"dwtDct\")  # 180x200\n// after\nif small_img.shape[0] * small_img.shape[1] < 256 * 256:\n    small_img = cv2.resize(small_img, (256, 256))\nencoder.encode(small_img, \"dwtDct\")","handlingStrategy":"validation","validationCode":"h, w = image.shape[:2]\nif h * w < 256 * 256:\n    image = cv2.resize(image, (max(256, w), max(256, h)), interpolation=cv2.INTER_CUBIC)","typeGuard":"def is_watermarkable(image) -> bool:\n    r, c = image.shape[0], image.shape[1]\n    return r * c >= 256 * 256","tryCatchPattern":"try:\n    encoded = encoder.encode(image, \"dwtDct\")\nexcept RuntimeError as e:\n    if \"image too small\" in str(e):\n        image = cv2.resize(image, (max(256, image.shape[1]), max(256, image.shape[0])))\n        encoded = encoder.encode(image, \"dwtDct\")\n    else:\n        raise","preventionTips":["Watermark full-resolution images before any downscaling","Check pixel count before encoding small outputs","Keep generated outputs at or above 256x256 when watermarking is required"],"tags":["watermark","image-size","vendored-code"],"backgroundTag":"image-too-small","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}