图像差异对比算法
Was having fun today with idiff.php
- a PHP shell script to tell you if two images are visually different by comparing them pixel by pixel. If there's a difference, the script creates a third image - black background with the different pixels in green. Only after writing the script I found that there's an imagemagick command compare
that does the same 🙂
今天很idiff.php
一个PHP shell脚本,通过逐像素比较两个图像来告诉您视觉上是否不同。 如果存在差异,则脚本将创建第三张图像-黑色背景,不同像素为绿色。 只有在编写脚本后,我才发现有一个imagemagick命令compare
,结果相同
剧本(the script)
The idea is that two GD images are created from the input files, also a third GD image with black background to store the diff. Loop through all the pixels and compare them one by one. If one is different, write a green pixel at the same location of the diff image.
这个想法是从输入文件中创建两个GD图像,还有另一个黑色背景的GD图像来存储差异。 遍历所有像素,然后将它们一一比较。 如果不同,则在差异图像的相同位置写入一个绿色像素。
<?php
/**
* Shell script to tell if two images are identical.
* If not, a third image is written - black background with the different pixels painted green
* Code partially inspired by and borrowed from http://pear.php.net/Image_Text test cases
*/
// check if th