Search code examples
phpimagecompare

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.


Solution

  • 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.