siyuan-note/siyuan · error

decode image failed:

Error message

decode image failed: 

What it means

image.DecodeConfig succeeded but the full imaging.Decode (with AutoOrientation) failed. The header is fine but the pixel body is corrupt, or the format/EXIF case is unsupported by the full decoder.

Source

Thrown at kernel/util/openai.go:647

	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 {
		decoded = imaging.Fit(decoded, maxEdge, maxEdge, imaging.Lanczos)
	}
	bounds = decoded.Bounds()
	if mimeType == "image/png" || mimeType == "image/webp" {
		var output bytes.Buffer

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Re-download or re-export the asset.
  2. Re-encode through an image tool to strip problem EXIF/color profile.
  3. Re-save as a plain JPEG/PNG.
Defensive patterns

Strategy: try-catch

Try / catch

img, err := util.PrepareModelImage(data, maxB, maxP, maxE)
if err != nil {
    log.Warnf("skip unreadable image: %s", err)
    continue
}

Prevention

When it happens

Trigger: Header intact but pixel body truncated; corrupt pixel stream; exotic color space / bit depth the full decoder cannot read; bad EXIF that confuses auto-orientation.

Common situations: Partially-downloaded JPEG; progressive JPEG cut mid-stream; rare CMYK color profile.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/aebc3098ba5a965f. Report an issue: GitHub.