mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-17 14:15:29 +01:00
🎨 Improve image export size for database assets fields https://github.com/siyuan-note/siyuan/issues/16470
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
6ee0b663e2
commit
3e6e5fa3a4
2 changed files with 26 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue