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)

  

posted @ 2021-01-02 12:55  Zel+_+  阅读(74)  评论(0编辑  收藏  举报