MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / NewImageHashFromBytes

Function NewImageHashFromBytes

testutil/image_hash.go:58–77  ·  view source on GitHub ↗

NewImageHashFromBytes loads an image from a byte slice and calculates its hash

(data []byte, hashType ImageHashType)

Source from the content-addressed store, hash-verified

56
57// NewImageHashFromBytes loads an image from a byte slice and calculates its hash
58func NewImageHashFromBytes(data []byte, hashType ImageHashType) (*ImageHash, error) {
59 h := &ImageHash{hashType: hashType}
60
61 switch hashType {
62 case HashTypeDct:
63 if err := h.calcDct2Hash(data); err != nil {
64 return nil, err
65 }
66
67 case HashTypeSHA256:
68 if err := h.calcSha256Hash(data); err != nil {
69 return nil, err
70 }
71
72 default:
73 return nil, fmt.Errorf("unsupported hash type: %d", hashType)
74 }
75
76 return h, nil
77}
78
79// Distance calculates the distance between two hashes
80// Returns error if hash types don't match

Callers 3

NewImageHashFunction · 0.85
NewImageHashFromPathFunction · 0.85
calculateHashMethod · 0.85

Calls 3

calcDct2HashMethod · 0.95
calcSha256HashMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected