2 回答

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
使用以下軟件包解決:“github.com/vincent-petithory/dataurl”
例如:
imgdecoded, _ := dataurl.Decode(imgupload)

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
正如圖像包的文檔(https://golang.org/pkg/image/92)中所述,您必須先注冊要使用的格式:
解碼任何特定的圖像格式需要事先注冊解碼器功能。注冊通常是自動(dòng)的,作為初始化該格式包的副作用,因此,要解碼 PNG 圖像,它就足夠了
導(dǎo)入_“圖片/png”
在程序的主包中。_ 意味著導(dǎo)入一個(gè)包純粹是為了它的初始化副作用。
實(shí)現(xiàn)示例: 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 關(guān)注
- 134 瀏覽
添加回答
舉報(bào)