{"record":{"id":"90e471907c5e6fc8","repo":"siyuan-note/siyuan","slug":"svg-images-are-not-accepted-by-multimodal-models","errorCode":null,"errorMessage":"SVG images are not accepted by multimodal models","messagePattern":"SVG images are not accepted by multimodal models","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":630,"sourceCode":"\t\t\treturn\n\t\t}\n\t\tseen[index] = true\n\t}\n\tmatched = true\n\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}","sourceCodeStart":612,"sourceCodeEnd":648,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/openai.go#L612-L648","documentation":"Multimodal vision models accept raster images only. PrepareModelImage detects SVG by mime OR by a literal '<svg' in the first 512 bytes (catching mis-detected or mislabeled SVGs) and rejects before decode.","triggerScenarios":"Attaching an SVG asset to a vision query; attaching a raster file whose extension says PNG/JPEG but whose content is SVG.","commonSituations":"SVG icons/illustrations dragged into a vision chat; asset renamed to .png but still SVG payload.","solutions":["Rasterize the SVG to PNG/JPEG before sending.","Do not attach SVGs to vision prompts.","Validate the true mime type before attaching."],"exampleFix":"# rasterize the SVG to PNG before attaching, or exclude it from the vision context","handlingStrategy":"validation","validationCode":"mt := mimetype.Detect(data).String()\nif strings.Contains(mt, \"svg\") ||\n    bytes.Contains(bytes.ToLower(data[:min(len(data),512)]), []byte(\"<svg\")) {\n    return errors.New(\"rasterize SVG before sending to a vision model\")\n}","typeGuard":"func IsSVG(data []byte) bool {\n    return strings.Contains(mimetype.Detect(data).String(), \"svg\") ||\n        bytes.Contains(bytes.ToLower(data[:min(len(data),512)]), []byte(\"<svg\"))\n}","tryCatchPattern":null,"preventionTips":["Exclude SVGs from multimodal contexts","Rasterize vector assets before vision queries"],"tags":["ai","multimodal","image","svg","go"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}