Go - 图片
// 获取图片宽度高度 需要引入格式包 "image/png"等
import (
"fmt"
"image"
_ "image/jpeg"
_ "image/png"
"os"
)
imagePath := "/public/logo.png"
file, _ := os.Open(imagePath)
defer file.Close()
img, _, err := image.Decode(file)
if err != nil {
fmt.Println(err.Error())
}
if img == nil {
fmt.Println("img 为 nil")
return
}
b := img.Bounds()
width := b.Max.X
height := b.Max.Y
println(width, height)

浙公网安备 33010602011771号