Compare 2 images in php

て烟熏妆下的殇ゞ 提交于 2019-11-26 05:28:24

问题


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?

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.


回答1:


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

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.




回答2:


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

}



回答3:


libpuzzle is a PHP extension that can compare images.




回答4:


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

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.




回答5:


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




回答6:


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)




回答7:


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.



来源:https://stackoverflow.com/questions/3270929/compare-2-images-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!