siyuan-note/siyuan · error
image exceeds pixel limit: %d
Error message
image exceeds pixel limit: %d
What it means
Decoded dimensions have width or height < 1 (invalid) OR width*height exceeds maxPixels. The guard prevents memory exhaustion and respects provider pixel caps.
Source
Thrown at kernel/util/openai.go:642
}
if maxBytes > 0 && len(data) > maxBytes {
return PreparedImage{}, fmt.Errorf("image exceeds size limit: %d bytes", maxBytes)
}
mimeType := mimetype.Detect(data).String()
if strings.Contains(mimeType, "svg") || bytes.Contains(bytes.ToLower(data[:min(len(data), 512)]), []byte("<svg")) {
return PreparedImage{}, errors.New("SVG images are not accepted by multimodal models")
}
switch mimeType {
case "image/gif", "image/jpeg", "image/png", "image/webp":
default:
return PreparedImage{}, fmt.Errorf("unsupported image type: %s", mimeType)
}
config, _, err := image.DecodeConfig(bytes.NewReader(data))
if err != nil {
return PreparedImage{}, errors.New("unsupported or invalid image: " + err.Error())
}
if config.Width < 1 || config.Height < 1 || maxPixels > 0 && int64(config.Width)*int64(config.Height) > int64(maxPixels) {
return PreparedImage{}, fmt.Errorf("image exceeds pixel limit: %d", maxPixels)
}
decoded, err := imaging.Decode(bytes.NewReader(data), imaging.AutoOrientation(true))
if err != nil {
return PreparedImage{}, errors.New("decode image failed: " + err.Error())
}
bounds := decoded.Bounds()
needsResize := maxEdge > 0 && (bounds.Dx() > maxEdge || bounds.Dy() > maxEdge)
if !needsResize && bounds.Dx() == config.Width && bounds.Dy() == config.Height && mimeType != "image/gif" {
return PreparedImage{
Data: data,
MIMEType: mimeType,
Width: bounds.Dx(),
Height: bounds.Dy(),
SourceSize: len(data),
}, nil
}
if needsResize {View on GitHub (pinned to 251596fc0d)
Solutions
- Downscale the source to within the provider's pixel budget before sending.
- Reject over-large images at the UI.
- Re-export malformed headers via an image editor.
Defensive patterns
Strategy: validation
Validate before calling
cfg, _, _ := image.DecodeConfig(bytes.NewReader(data))
if maxPixels > 0 && int64(cfg.Width)*int64(cfg.Height) > int64(maxPixels) {
return errors.New("downscale the image before sending")
} Type guard
func WithinPixelLimit(data []byte, maxPixels int) bool {
cfg, _, err := image.DecodeConfig(bytes.NewReader(data))
if err != nil { return false }
return maxPixels <= 0 || int64(cfg.Width)*int64(cfg.Height) <= int64(maxPixels)
} Prevention
- Downscale large photos before attaching
- Enforce the pixel budget in the UI
When it happens
Trigger: A very high-resolution photo (e.g. 8000x8000) exceeds the provider's megapixel cap; or a degenerate image whose header reports zero/tiny dimensions.
Common situations: Full-resolution DSLR or phone panoramas; stitched images; malformed header reporting tiny dimensions.
Related errors
- image exceeds size limit: %d bytes
- prepared image exceeds size limit: %d bytes
- image data is empty
- SVG images are not accepted by multimodal models
- unsupported image type: %s
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/6c06297274388301.
Report an issue: GitHub.