enhance(hash):包装散列算法中的错误提示。

This commit is contained in:
徐涛
2023-07-13 13:58:53 +08:00
parent 2e276ca33c
commit 955d3a96f2
9 changed files with 27 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ package phash
import (
"encoding/binary"
"encoding/hex"
"fmt"
"image"
"os"
@@ -27,13 +28,13 @@ func HashHex(image image.Image) string {
func HashFile(file string) ([]byte, error) {
f, err := os.Open(file)
if err != nil {
return nil, err
return nil, fmt.Errorf("未能打开指定文件,%w", err)
}
defer f.Close()
img, _, err := image.Decode(f)
if err != nil {
return nil, err
return nil, fmt.Errorf("未能解码指定图像文件,%w", err)
}
return Hash(img), nil
}