壳牌测试“图像是不同的”? [英] Shell test for "images are different"?
问题描述
在shell脚本中,我想检查两个PNG图像是否在图像具有不同尺寸或者一个图像的至少一个像素具有与另一图像的对应像素不同的RGBA的意义上是不同的。
In a shell script, I would like to check whether two PNG images are different in the sense that either the images have different sizes or at least one pixel of one image has a different RGBA than the corresponding pixel of the other image.
哈希这两个图像文件不起作用,因为图像可能被压缩不同或有不同的注释,或者两个像素完全透明但RGB组件不同等。
Hashing the two image files will not work because the images could be compressed differently or have a different comment or perhaps two pixels are fully transparent but the RGB components differ, etc.
我知道如何使用ImageMagick的 convert
实用程序检查文件大小是否不同。至于比较像素值,我想到使用ImageMagick的比较
实用程序,但如果命令成功处理,则退出代码始终为0: http://www.imagemagick.org/discourse-server/viewtopic.php?f= 3& t = 22451
I know how to check whether the file sizes are different using ImageMagick's convert
utility. As far as comparing the pixel values, I thought of using ImageMagick's compare
utility, but the exit code is always 0 if the command was successfully processed: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=22451
可以使用哪种命令行测试来比较两个PNG图像的像素是否相等?或者也许有一种方法可以使用比较
?
What command line test can be used to compare the pixels of two PNG images for equality? Or perhaps there is a way to use compare
after all?
推荐答案
找到一种图像格式,允许未压缩的RGBA,转换这两个文件,并比较输出。也许是这样的:
Find an image format which allows uncompressed RGBA, convert both files, and compare the output. Maybe something like this:
$ convert a.png a.rgba
$ convert b.png b.rgba
$ cmp {a,b}.rgba
a.rgba b.rgba differ: byte 1, line 1
这篇关于壳牌测试“图像是不同的”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!