{"record":{"id":"e28e5059d4fa8b4b","repo":"siyuan-note/siyuan","slug":"unsupported-image-type-s","errorCode":null,"errorMessage":"unsupported image type: %s","messagePattern":"unsupported image type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":635,"sourceCode":"\treturn\n}\n\n// PrepareModelImage 校验并按需缩放图片，尽量保留多模态模型支持的原始格式和图片质量。\nfunc PrepareModelImage(data []byte, maxBytes, maxPixels, maxEdge int) (PreparedImage, error) {\n\tif len(data) == 0 {\n\t\treturn PreparedImage{}, errors.New(\"image data is empty\")\n\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,","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/openai.go#L617-L653","documentation":"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.","triggerScenarios":"Attaching a BMP, TIFF, HEIC, AVIF, or ICO file to a vision query.","commonSituations":"iPhone HEIC uploads; screenshots saved as BMP; raw camera TIFF or PSD exports.","solutions":["Convert the image to PNG, JPEG, WebP, or GIF before attaching.","For HEIC from phones, enable HEIC-to-JPEG conversion on import.","Standardize client-side exports to JPEG/PNG."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"switch mimetype.Detect(data).String() {\ncase \"image/gif\", \"image/jpeg\", \"image/png\", \"image/webp\":\ndefault:\n    return errors.New(\"convert to PNG/JPEG/WebP/GIF first\")\n}","typeGuard":"func IsAcceptedRasterImage(data []byte) bool {\n    switch mimetype.Detect(data).String() {\n    case \"image/gif\", \"image/jpeg\", \"image/png\", \"image/webp\":\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Standardize on PNG/JPEG/WebP for vision inputs","Convert HEIC/RAW on import"],"tags":["ai","multimodal","image","go","format"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}