package tool

import (
	"image"
	_ "image/jpeg"
	_ "image/png"
	"net/http"

	_ "golang.org/x/image/webp"
)

// GetImgSize 获取图片大小：宽，高
func GetImgSize(imgUrl string) (width, height int32, err error) {
	if imgUrl == "" {
		return
	}

	var resp *http.Response
	resp, err = http.Get(imgUrl)
	if err != nil {
		return
	}
	defer resp.Body.Close()

	config, _, err := image.DecodeConfig(resp.Body)
	if err != nil {
		return
	}

	width = int32(config.Width)
	height = int32(config.Height)
	return
}
