media-picker/core/webp.go

26 lines
635 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package core
import (
"fmt"
"golang.org/x/image/webp"
"os"
)
// 读取webp格式的图片信息
func readWebpTypeImage(webpFilePath string) (err error, width int, height int) {
// 打开WebP文件
file, err := os.Open(webpFilePath)
if err != nil {
fmt.Printf("=== Failed to open file: %v\n", err)
return err, 0, 0
}
defer file.Close()
// 使用webp.DecodeConfig解码WebP图片配置信息不加载完整像素数据
imgConfig, err := webp.DecodeConfig(file)
if err != nil {
fmt.Printf("=== Failed to decode WebP image config: %v\n", err)
return err, 0, 0
}
return nil, imgConfig.Width, imgConfig.Height
}