Created
July 7, 2017 07:14
-
-
Save jckimble/a038ca921435867f00218522439f9693 to your computer and use it in GitHub Desktop.
Checking if image is same image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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