if diff.getbbox() isNone: # 图片间没有任何不同则直接退出 print("【+】We are the same!") else: diff.save(diff_save_location) except ValueError as e: text = ("表示图片大小和box对应的宽度不一致,参考API说明:Pastes another image into this image." "The box argument is either a 2-tuple giving the upper left corner, a 4-tuple defining the left, upper, " "right, and lower pixel coordinate, or None (same as (0, 0)). If a 4-tuple is given, the size of the pasted " "image must match the size of the region.使用2纬的box避免上述问题") print("【{0}】{1}".format(e,text))
if __name__ == '__main__': compare_images('1.png', '2.png', '我们不一样.png')