go-bot/utils/image2base64.go

22 lines
321 B
Go
Raw Normal View History

package utils
import (
"encoding/base64"
"io"
"os"
)
func Image2Base64(path string) string {
file, err := os.Open(path)
if err != nil {
return ""
}
defer file.Close()
if data, err := io.ReadAll(file); err == nil {
return "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(data)
}
return ""
}