123456789101112131415161718192021222324252627282930 |
- package common
- import (
- "lzyd-user-api/utils"
- "path"
- "time"
- )
- func GetImagePath(filename string) string {
- if len(filename) > 0 {
- savePath := path.Join(ImageInfo.BasePath, ImageInfo.OutputDir)
- savePath = path.Join(savePath, time.Now().Format("2006-01"))
- if err := utils.IsNotExistMkDirAll(savePath); err == nil {
- suffix := path.Ext(filename)
- if len(suffix) == 0 {
- suffix = ".jpg"
- }
- return path.Join(savePath, utils.RandImageName(12)+suffix)
- }
- }
- return ""
- }
- func GetImageURLFromPath(path string) string {
- if len(path) > 0 {
- length := len(ImageInfo.BasePath)
- return ImageInfo.PrefixURL + path[length:]
- }
- return ""
- }
|