比较 php 中的 2 个图像 [英] Compare 2 images in php

查看:17
本文介绍了比较 php 中的 2 个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 张相同大小的图像来创建洋葱皮效果,其中 1 个为 50%,另一个为 50%.

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.

推荐答案

大多数其他答案都涉及使用各种散列函数.问题明确地询问比较图像的内容,而不是比较文件.

Most of the other answers refer to using various hashing functions. The question explicitly is asking about comparing the contents of the images, not about comparing the files.

这意味着您最终必须真正理解图像的内容.在 PHP 中有两个常用的扩展,ImageMagick 和 GD.

This means you end up having to actually understand the contents of the image. In PHP there are two extensions often used for this, ImageMagick and GD.

ImageMagick 通过 PHP ImageMagick 扩展程序提供了多种工具供您使用.

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

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

最大的问题是该库的文档几乎不存在,因此将涉及大量反复试验.PHP 扩展是 ImageMagick 库的一个非常薄的包装器,因此可以在 ImageMagick 文档中找到 compareimages() 函数行为的详细信息.

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. The PHP extension is a pretty thin wrapper around the ImageMagick library, so details of how the compareimages() function behaves can be found in the ImageMagick documentation.

这篇关于比较 php 中的 2 个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆