Calculate dhash for jpgs

This commit is contained in:
Jan Bader
2023-12-04 22:59:55 +01:00
parent b58151efb7
commit bbdc296cbd
4 changed files with 28 additions and 0 deletions

17
file.go
View File

@@ -3,10 +3,14 @@ package main
import (
"crypto/sha1"
"encoding/base64"
"image/jpeg"
"io"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/corona10/goimagehash"
)
func remove(path string) {
@@ -48,6 +52,19 @@ func calculateHash(path string) (string, error) {
}
defer f.Close()
if strings.HasSuffix(path, ".jpg") {
img, err := jpeg.Decode(f)
if err != nil {
return "", err
}
hash, err := goimagehash.DifferenceHash(img)
if err != nil {
return "", err
}
return hash.ToString(), nil
}
h := sha1.New()
if _, err := io.Copy(h, f); err != nil {
return "", err