2 回答
TA貢獻1811條經驗 獲得超6個贊
使用以下軟件包解決:“github.com/vincent-petithory/dataurl”
例如:
imgdecoded, _ := dataurl.Decode(imgupload)
TA貢獻1810條經驗 獲得超4個贊
正如圖像包的文檔(https://golang.org/pkg/image/92)中所述,您必須先注冊要使用的格式:
解碼任何特定的圖像格式需要事先注冊解碼器功能。注冊通常是自動的,作為初始化該格式包的副作用,因此,要解碼 PNG 圖像,它就足夠了
導入_“圖片/png”
在程序的主包中。_ 意味著導入一個包純粹是為了它的初始化副作用。
實現示例: https: //play.golang.org/p/7d1gS7_tdc0
import (
"image"
// Package image/jpeg is not used explicitly in the code below,
// but is imported for its initialization side-effect, which allows
// image.Decode to understand JPEG formatted images.
_ "image/jpeg"
"io"
)
func ImgCheckSize(file io.Reader) (io.Reader, error) {
config, format, err := image.DecodeConfig(file)
...
- 2 回答
- 0 關注
- 151 瀏覽
添加回答
舉報
