{"record":{"id":"0c4da7a1b0000195","repo":"SubtitleEdit/subtitleedit","slug":"image-dimensions-are-larger-than-1000x1000","errorCode":null,"errorMessage":"Image dimensions are larger than 1000x1000","messagePattern":"Image dimensions are larger than 1000x1000","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/Ocr/GoogleLens/Core.cs","lineNumber":247,"sourceCode":"    {\n        if (!Constants.SUPPORTED_MIMES.Contains(mime))\n        {\n            throw new Exception(\"File type not supported\");\n        }\n        if (originalDimensions == null)\n        {\n            throw new Exception(\"Original dimensions not set\");\n        }\n\n        string fileName = $\"image.{Constants.MIME_TO_EXT[mime]}\";\n        var dimensions = Helper.ImageDimensionsFromData(uint8);\n\n        var width = dimensions.Width;\n        var height = dimensions.Height;\n\n        if (width > 1000 || height > 1000)\n        {\n            throw new Exception(\"Image dimensions are larger than 1000x1000\");\n        }\n\n        var file = new ByteArrayContent(uint8);\n        file.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(mime);\n        var formdata = new MultipartFormDataContent\n        {\n            { file, \"encoded_image\", fileName },\n            { new StringContent(width.ToString()), \"original_width\" },\n            { new StringContent(height.ToString()), \"original_height\" },\n            { new StringContent($\"{width},{height}\"), \"processed_image_dimensions\" }\n        };\n\n        return await FetchAsync(formdata, originalDimensions);\n    }\n    \n    private void GenerateCookieHeader(Dictionary<string, string> header)\n    {\n        if (HeaderData.Cookies.Count > 0)","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/Ocr/GoogleLens/Core.cs#L229-L265","documentation":"Thrown by Core.ScanByData when the image's own width or height (as measured from the bytes via Helper.ImageDimensionsFromData) exceeds 1000px. Unlike ScanByBufferAsync which auto-resizes before calling ScanByData, ScanByData expects an already-conformant image and refuses oversized input rather than silently resizing. Lens rejects images larger than 1000x1000, so this is a hard precondition.","triggerScenarios":"Calling ScanByData directly with a large image without first downscaling, or calling it after a code path that skips the ScanByBufferAsync resize step.","commonSituations":"A caller uses ScanByData instead of ScanByBufferAsync and passes a full-resolution screenshot; the resize step was bypassed; an upstream producer did not enforce the 1000px limit.","solutions":["Pre-resize the image to fit within 1000x1000 (maintaining aspect ratio) before ScanByData.","Use ScanByBufferAsync, which performs the resize automatically.","Apply Helper.ResizeImageAsync(buffer, 1000, 1000) before invoking ScanByData.","Reject/guide the user to a smaller image at the UI layer."],"exampleFix":"// before\nvar result = await core.ScanByData(bigBytes, 'image/png', dims);\n\n// after\nif (width > 1000 || height > 1000) bigBytes = await Helper.ResizeImageAsync(bigBytes, 1000, 1000);\nvar result = await core.ScanByData(bigBytes, 'image/png', dims);","handlingStrategy":"validation","validationCode":"var (w, h) = Helper.ImageDimensionsFromData(bytes);\nif (w > 1000 || h > 1000) bytes = await Helper.ResizeImageAsync(bytes, 1000, 1000);\nvar r = await core.ScanByData(bytes, mime, dims);","typeGuard":"static bool FitsLensLimit(byte[] b) { var (w,h) = Helper.ImageDimensionsFromData(b); return w <= 1000 && h <= 1000; }","tryCatchPattern":"try { var r = await core.ScanByData(bytes, mime, dims); }\ncatch (Exception ex) when (ex.Message.Contains(\"larger than 1000x1000\")) { bytes = await Helper.ResizeImageAsync(bytes, 1000, 1000); /* retry */ }","preventionTips":["Pre-resize images to <= 1000x1000 before ScanByData.","Use ScanByBufferAsync for automatic resizing.","Enforce the limit at the UI/picker layer.","Always pass already-conformant images to ScanByData."],"tags":["google-lens","ocr","image","resize","validation"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}