我想使用 PHP 脚本比较两个图像。其中一张图片位于我的服务器上,另一张位于外部网站上。我试图将两个图像的哈希值相互比较。不幸的是,这仅在将两张图像保存在我的服务器上时才有效。我怎样才能使它工作?
<?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
}
?>
最佳答案
如果您使用的是 php 5.1+(我希望如此),您可以这样写:
<?php
$localimage = sha1_file('image.jpg');
$ext_image = sha1_file('http://www.google.com/image.jpg');
if($localimage == $ext_image){
//Do something
}
?>
因为 sha1_file 将在远程包装器上工作。
引自 PHP 文档 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/..')
关于php - 在 PHP 中从远程位置散列图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32587851/