user1216398
user1216398

Reputation: 1950

create hash from image contents with PHP?

I currently create a hash from an image name but would rather create a hash based on the contents of an image so I can detect duplicate images. Are their any PHP classes that do this?

My current code is very simple:

$image = "image1.jpg"; 
$filehash = md5_file($image );

Upvotes: 3

Views: 4171

Answers (2)

Maurits
Maurits

Reputation: 2114

As you mention content, you might want to have a look at a perceptual hash, such as phash

Upvotes: 3

Brad
Brad

Reputation: 163334

The current code you have is actually calculating the md5 of the file contents. What you already have does what you want.

Upvotes: 6

Related Questions