Files
huangguo_server/common/picture.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

39 lines
728 B
Go

package common
import (
"bytes"
"image"
"io"
"net/http"
)
type PictureProp struct {
Size int `json:"size" bson:"size,omitempty"` // 单位:b
Width int `json:"height" bson:"height,omitempty"`
Height int `json:"width" bson:"width,omitempty"`
}
const ImgUrlHost = "http://image.lhexm.com/"
func GetPictureProp(imgURL string) PictureProp {
res, err := http.Get(imgURL)
if err != nil {
return PictureProp{}
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return PictureProp{}
}
buf := bytes.NewBuffer(body)
cfg, _, err := image.DecodeConfig(buf)
if err != nil {
return PictureProp{}
}
return PictureProp{
Size: len(body),
Width: cfg.Width,
Height: cfg.Height,
}
}