An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve image export size for database assets fields https://github.com/siyuan-note/siyuan/issues/16470
Daniel3e6e5fa3a41d
diff --git a/kernel/model/assets.go b/kernel/model/assets.goindex 15de3f68b4..5f6dfdabf0 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -51,6 +51,24 @@ import ("github.com/siyuan-note/siyuan/kernel/util")+func GetAssetImgSize(assetPath string) (width, height int) {+ absPath, err := GetAssetAbsPath(assetPath)+ if err != nil {+ logging.LogErrorf("get asset [%s] abs path failed: %s", assetPath, err)+ return+ }++ img, err := imaging.Open(absPath)+ if err != nil {+ logging.LogErrorf("open asset image [%s] failed: %s", absPath, err)+ return+ }++ width = img.Bounds().Dx()+ height = img.Bounds().Dy()+ return+}+func GetAssetPathByHash(hash string) string {assetHash := cache.GetAssetHash(hash)if nil == assetHash {diff --git a/kernel/model/export.go b/kernel/model/export.goindex dc53d7cbe8..1c8781d327 100644--- a/kernel/model/export.go+++ b/kernel/model/export.go@@ -2831,10 +2831,14 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,img.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: []byte(a.Content)})img.AppendChild(&ast.Node{Type: ast.NodeCloseParen})mdTableCell.AppendChild(img)- height := "height: 128px;"- spanIAL := &ast.Node{Type: ast.NodeKramdownSpanIAL, Tokens: []byte("style=\"" + height + "\"")}- mdTableCell.AppendChild(spanIAL)- img.SetIALAttr("style", height)+ img.SetIALAttr("style", "max-height: 128px;")++ width, height := GetAssetImgSize(a.Content)+ if height > 128 {+ img.SetIALAttr("height", "128px")+ newWidth := int(float64(width) * (128.0 / float64(height)))+ img.SetIALAttr("width", strconv.Itoa(newWidth)+"px")+ }} else if av.AssetTypeFile == a.Type {linkText := strings.TrimSpace(a.Name)if "" == linkText {