Skip to content

Instantly share code, notes, and snippets.

@jckimble
Created July 7, 2017 07:14
Show Gist options
  • Save jckimble/a038ca921435867f00218522439f9693 to your computer and use it in GitHub Desktop.
Save jckimble/a038ca921435867f00218522439f9693 to your computer and use it in GitHub Desktop.
Checking if image is same image
<?php
function getImageHash($filename){
$content=file_get_contents($filename);
if($content){
list($width,$height,$type,$attr)=getimagesize($filename);
$im=imagecreatefromstring($content);
$new=imagecreatetruecolor($width,$height);
imagecopy($new,$im,0,0,0,0,$width,$height,$width,$height);
imagedestroy($im);
ob_start();
imagegif($new);
$data=ob_get_contents();
ob_end_clean();
imagedestroy($new);
return md5($data);
}
return "";
}
$hash=getImageHash("test.jpg");
$hash2=getImageHash("test.png");
if($hash==$hash2){
echo "Same Image";
}else{
echo "Different Image";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment