mirror of
https://github.com/JaCoB1123/dupe-finder.git
synced 2025-12-15 07:45:14 +01:00
Calculate dhash for jpgs
This commit is contained in:
17
file.go
17
file.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user