{"record":{"id":"6c06297274388301","repo":"siyuan-note/siyuan","slug":"image-exceeds-pixel-limit-d","errorCode":null,"errorMessage":"image exceeds pixel limit: %d","messagePattern":"image exceeds pixel limit: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":782,"sourceCode":"\t}\n\tif maxBytes > 0 && len(data) > maxBytes {\n\t\treturn PreparedImage{}, fmt.Errorf(\"image exceeds size limit: %d bytes\", maxBytes)\n\t}\n\tmimeType := mimetype.Detect(data).String()\n\tif strings.Contains(mimeType, \"svg\") || bytes.Contains(bytes.ToLower(data[:min(len(data), 512)]), []byte(\"<svg\")) {\n\t\treturn PreparedImage{}, errors.New(\"SVG images are not accepted by multimodal models\")\n\t}\n\tswitch mimeType {\n\tcase \"image/gif\", \"image/jpeg\", \"image/png\", \"image/webp\":\n\tdefault:\n\t\treturn PreparedImage{}, fmt.Errorf(\"unsupported image type: %s\", mimeType)\n\t}\n\tconfig, _, err := image.DecodeConfig(bytes.NewReader(data))\n\tif err != nil {\n\t\treturn PreparedImage{}, errors.New(\"unsupported or invalid image: \" + err.Error())\n\t}\n\tif config.Width < 1 || config.Height < 1 || maxPixels > 0 && int64(config.Width)*int64(config.Height) > int64(maxPixels) {\n\t\treturn PreparedImage{}, fmt.Errorf(\"image exceeds pixel limit: %d\", maxPixels)\n\t}\n\n\tdecoded, err := imaging.Decode(bytes.NewReader(data), imaging.AutoOrientation(true))\n\tif err != nil {\n\t\treturn PreparedImage{}, errors.New(\"decode image failed: \" + err.Error())\n\t}\n\tbounds := decoded.Bounds()\n\tneedsResize := maxEdge > 0 && (bounds.Dx() > maxEdge || bounds.Dy() > maxEdge)\n\tif !needsResize && bounds.Dx() == config.Width && bounds.Dy() == config.Height && mimeType != \"image/gif\" {\n\t\treturn PreparedImage{\n\t\t\tData:       data,\n\t\t\tMIMEType:   mimeType,\n\t\t\tWidth:      bounds.Dx(),\n\t\t\tHeight:     bounds.Dy(),\n\t\t\tSourceSize: len(data),\n\t\t}, nil\n\t}\n\tif needsResize {","sourceCodeStart":764,"sourceCodeEnd":800,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai.go#L764-L800","documentation":"Thrown when an image decodes structurally but its pixel dimensions fail the configured constraint in kernel/util/openai.go: config.Width or config.Height is less than 1, or width*height exceeds the maxPixels budget. The %d value in the message is the pixel budget that was exceeded (0 means no pixel cap was set, so a <1 dimension triggered it).","triggerScenarios":"Calling the image preparation function with an image whose width*height is greater than maxPixels, or with a decoded 0-width/0-height image while maxPixels > 0.","commonSituations":"Users paste 50-megapixel camera photos or 8K screenshots; a caller passes maxPixels=0 intending 'unlimited' but the image also has zero dimensions; a tightly configured maxPixels rejects images that worked before the limit was tightened.","solutions":["Resize or downscale the image so width*height is within the limit before sending it","Increase the maxPixels configuration value in the AI image settings if the budget is too small","If the message shows limit 0 with a genuinely broken image, replace the corrupt source file","Crop the image to the region of interest to cut pixel count"],"exampleFix":"// before\nimg, err := prepareImage(data, mime, 4096*4096, 2048, 8<<20)\n// after: pre-check pixels and downscale first\nif w*h > 4096*4096 {\n    data, _ = downscaleToWithinPixelBudget(data, 4096*4096)\n}\nimg, err := prepareImage(data, mime, 4096*4096, 2048, 8<<20)","handlingStrategy":"validation","validationCode":"cfg, _, err := image.DecodeConfig(bytes.NewReader(data))\nif err != nil { return err }\nif cfg.Width < 1 || cfg.Height < 1 { return errors.New(\"zero-dimension image\") }\nif int64(cfg.Width)*int64(cfg.Height) > 4096*4096 {\n    return errors.New(\"image too large; downscale first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decode config (cheap) and check dimensions before full processing","Set a generous but real maxPixels budget instead of relying on defaults","Pre-downscale camera photos and 4K/8K screenshots before sending to AI","When raising limits, re-check the pixel math: width*height, not max edge"],"tags":["image","size-limit","dimensions","ai"],"backgroundTag":"value-out-of-range","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}