与PHP中的输入图像进行比较后,在目录中输出相似的图像
在我的网页中,用户将上传图像,然后提交后,应将其与目录中的所有图像进行比较,并输出相似的图像。我使用MD5进行了此操作,但它只会输出精确的图像,我知道原因,但我不知道如何使用RGB比较使用输入的图像循环所有图像...有人可以帮助我。这是我当前的代码:
<?php
if(isset($_POST['submit'])){
$filepath=pathinfo($_FILES['file']['name']) ;
$extension=$filepath['extension'];
$iname= date('H-i-s').'.'.$extension;
$path='upload/'.$iname;
if(move_uploaded_file($_FILES['file']['tmp_name'],$path)){
$img=$path;
echo $img;
$f=md5(file_get_contents($img));
$images=glob("img/*");
foreach($images as $image){
if($f==md5(file_get_contents($image))){
echo "<img height='70px' width='70px' src='".$image."'/>";
}
}
}
}
?>
和我的HTML代码
<html>
<body>
<form method=post enctype="multipart/form-data">
<input type=file name=file><br><input type=submit name=submit value=submit>
</form>
</body>
</html>
In my web page a user will upload an image then after submit it should be compared with all images in a directory and output similar images. I did this with md5 but it will output only exact images and I know the reason but I don't know how to loop all images in my directory with the inputted image using RGB comparisons... Can somebody please help me. Here is my current code:
<?php
if(isset($_POST['submit'])){
$filepath=pathinfo($_FILES['file']['name']) ;
$extension=$filepath['extension'];
$iname= date('H-i-s').'.'.$extension;
$path='upload/'.$iname;
if(move_uploaded_file($_FILES['file']['tmp_name'],$path)){
$img=$path;
echo $img;
$f=md5(file_get_contents($img));
$images=glob("img/*");
foreach($images as $image){
if($f==md5(file_get_contents($image))){
echo "<img height='70px' width='70px' src='".$image."'/>";
}
}
}
}
?>
And my html code
<html>
<body>
<form method=post enctype="multipart/form-data">
<input type=file name=file><br><input type=submit name=submit value=submit>
</form>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用了此GIT存储库中提到的类,该类别计算了图像哈希及其差异。
https://github.com/nvthaovn/compareimage
并更改了我的代码:
I used the class mentioned in this git repo that calculates the image hashes and their differences.
https://github.com/nvthaovn/CompareImage
and changed my code to this: