比较 php 中的 2 个图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3270929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:11:26  来源:igfitidea点击:

Compare 2 images in php

phpimagegdcomparemd5

提问by Joseph

Comparing 2 images to see if they are both the same files are easy, threw the files MD5, but is it possible or even plausible to determine if 2 images are same by using PHP GD to get the difference of the two images. If we where to get the difference of the two, and it was all white (id assume white or even black), then we would now know its both the same photo?

比较 2 个图像以查看它们是否是相同的文件很容易,抛出文件 MD5,但是通过使用 PHP GD 来确定 2 个图像是否相同以获得两个图像的差异是否可能甚至合理。如果我们从哪里得到两者的区别,而且都是白色的(假设是白色甚至黑色),那么我们现在就知道它们是同一张照片?

Also side note: id like to know if its possible to get 2 images of equal size to create an onion skin effect, 50% transparency on 1 and 50% on the other.

另附注:我想知道是否有可能获得 2 张相同大小的图像来创建洋葱皮效果,其中 1 个为 50%,另一个为 50%。

采纳答案by kander

ImageMagick offers various tools you can use for this, through the PHP ImageMagick extension.

ImageMagick 通过 PHP ImageMagick 扩展提供了各种工具,您可以为此使用它。

http://www.php.net/manual/en/function.imagick-compareimages.php

http://www.php.net/manual/en/function.imagick-compareimages.php

Biggest problem is that the documentation for that library is pretty much non-existing, so there will be a lot of trial-and-error involved.

最大的问题是该库的文档几乎不存在,因此将涉及大量反复试验。

回答by Hamada Mido

$md5image1 = md5(file_get_contents($image1));
$md5image2 = md5(file_get_contents($image2));
if ($md5image1 == $md5image2) {

}

回答by pfrenssen

libpuzzleis a PHP extension that can compare images.

libpuzzle是一个可以比较图像的 PHP 扩展。

回答by Pat Cullen

A similar question was asked on this Stackoverflow threadand I had developed something for my own use. Posting it here so that it may help others.

在这个Stackoverflow 线程上提出了一个类似的问题,我开发了一些供自己使用的东西。把它张贴在这里,以便它可以帮助其他人。

It takes two (or more images) and gives you options about checking the difference between them. Options like resolution to use, and strictness.

它需要两张(或更多张)图像,并为您提供检查它们之间差异的选项。使用分辨率和严格性等选项。

I wrote a more comprehensive blogpost on it as well.

我也写了一篇关于它的更全面的博客文章

回答by TechNikh

Image Comparison Function in PHP with GD Library http://www.robert-lerner.com/imagecompare.php

PHP 中的图像比较功能与 GD 库 http://www.robert-lerner.com/imagecompare.php

回答by mrd081

If you are comparing just two files then hashing data and then comparing is perfect solution. If you are comparing large number of files, then better sort them first based on size and then compare only with same size.

如果您只比较两个文件,那么散列数据然后比较是完美的解决方案。如果您要比较大量文件,最好先根据大小对它们进行排序,然后仅与相同大​​小的文件进行比较。

回答by Sarfraz

Not sure whether it is that easy and a solution exits but probably you may get an idea of image detection from:

不确定它是否那么容易并且存在解决方案,但您可能会从以下方面了解图像检测:

Face detection with PHP
Image Nudity Filter (Class)

使用 PHP Image Nudity Filter 进行人脸检测
(类)