siyuan-note/siyuan · error

unsupported image type: %s

Error message

unsupported image type: %s

What it means

After SVG exclusion, PrepareModelImage accepts only gif/jpeg/png/webp mime types. Any other raster format (BMP, TIFF, HEIC, AVIF, ICO) is rejected with its detected mime.

Source

Thrown at kernel/util/openai.go:635

	return
}

// PrepareModelImage 校验并按需缩放图片,尽量保留多模态模型支持的原始格式和图片质量。
func PrepareModelImage(data []byte, maxBytes, maxPixels, maxEdge int) (PreparedImage, error) {
	if len(data) == 0 {
		return PreparedImage{}, errors.New("image data is empty")
	}
	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,

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Convert the image to PNG, JPEG, WebP, or GIF before attaching.
  2. For HEIC from phones, enable HEIC-to-JPEG conversion on import.
  3. Standardize client-side exports to JPEG/PNG.
Defensive patterns

Strategy: validation

Validate before calling

switch mimetype.Detect(data).String() {
case "image/gif", "image/jpeg", "image/png", "image/webp":
default:
    return errors.New("convert to PNG/JPEG/WebP/GIF first")
}

Type guard

func IsAcceptedRasterImage(data []byte) bool {
    switch mimetype.Detect(data).String() {
    case "image/gif", "image/jpeg", "image/png", "image/webp":
        return true
    }
    return false
}

Prevention

When it happens

Trigger: Attaching a BMP, TIFF, HEIC, AVIF, or ICO file to a vision query.

Common situations: iPhone HEIC uploads; screenshots saved as BMP; raw camera TIFF or PSD exports.

Related errors


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