Using a PHP script, I want to compare two images. One of the images is located on my server, and one is located on an external website. I have tried to compare the hashes of the two images to each other. Unfortunately, this only works when the two images are saved on my server. How can I make this work?
<?php
$localimage = sha1_file('image.jpg');
$imagelink = file_get_contents('http://www.google.com/image.jpg');
$ext_image = sha1_file($imagelink);
if($localimage == $ext_image){
//Do something
}
?>
If you are using php 5.1+ (which I hope) you can just write :
<?php
$localimage = sha1_file('image.jpg');
$ext_image = sha1_file('http://www.google.com/image.jpg');
if($localimage == $ext_image){
//Do something
}
?>
As sha1_file will work on remote wrappers.
Quote from PHP doc at https://secure.php.net/manual/en/function.sha1-file.php
5.1.0 Changed the function to use the streams API. It means that you can use it with wrappers, like sha1_file('http://example.com/..')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With