mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-14 06:07:36 +08:00
feat: only attempt to parse image attachments
This commit is contained in:
parent
6f18a47ed0
commit
9795f74f0f
@ -222,11 +222,15 @@ func prepareAttachment(opener vfs.Opener, base, name string) (Attachment, error)
|
|||||||
Replace: name,
|
Replace: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to detect image dimensions
|
// Try to detect image dimensions if it's an image attachment
|
||||||
|
ext := strings.ToLower(filepath.Ext(name))
|
||||||
|
switch ext {
|
||||||
|
case ".jpg", ".jpeg", ".png", ".gif":
|
||||||
if config, _, err := image.DecodeConfig(bytes.NewReader(fileBytes)); err == nil {
|
if config, _, err := image.DecodeConfig(bytes.NewReader(fileBytes)); err == nil {
|
||||||
attachment.Width = strconv.Itoa(config.Width)
|
attachment.Width = strconv.Itoa(config.Width)
|
||||||
attachment.Height = strconv.Itoa(config.Height)
|
attachment.Height = strconv.Itoa(config.Height)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return attachment, nil
|
return attachment, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user