Lono
Lono

Reputation: 33

Compare Raw Image Data PHP

I'm trying to make a PHP script that updates photos. I receive the raw image data from the source, and I want to compare it to the existing file I have to see if I should download it. I'll post the idea of what I'm looking to do.

$contents = file_get_contents($directory);
$new_photo = Photo["Data"];
echo strcmp($liph_id_contents,$photo['Data']==0);

This doesn't work, but I hope you get the idea. The images I am trying to compare are .jpg

Photo["Data"] is raw image data

$directory is the location of a stored image file

Update: I'm able to convert the two images in to PHP image resources. A comparison between image resources would also suffice.

Update: I found a class to use to compare two image resources in PHP. Take a look at http://compareimages.nikhazy-dizajn.hu/ I made a slight change to the compare function in the class to let it take PHP image resources instead.

Upvotes: 2

Views: 229

Answers (2)

Lono
Lono

Reputation: 33

I found a class to use to compare two image resources in PHP. Take a look at http://compareimages.nikhazy-dizajn.hu/ I made a slight change to the compare function in the class to let it take PHP image resources instead.

Upvotes: 0

Gabe
Gabe

Reputation: 1183

Use sha1_file() instead, like you do when you download software from the internet and want to veryfy it has not been altered.

if (sha1_file($directory) == sha1_file(Photo["Data"])) 
   echo "indentical";
else
   echo "not identical";

If both files are identical they will return the same hash.

Upvotes: 1

Related Questions