我目前正在移动一个脚本,从图像从Windows主机创建本地敏感哈希到debian之一。
我的问题是Pillow从两个平台上的相同源图像返回不同的图像数据。
我只观察jpegs的这种行为。
测试用例:不同的图像数据来自同一个来源与枕头
from PIL import Image
import md5
import urllib2
from cStringIO import StringIO
urls = ("https://i.imgur.com/Mx6NQwM.jpg","https://i.imgur.com/MN1TKu5.png")
print("VERSION %s" % Image.VERSION)
for url in urls:
response = urllib2.urlopen(url).read()
img = Image.open(StringIO(response)).convert("RGB")
img_md5 = "".join("".join(map(chr, x)) for x in img.getdata())
print("URL: %s" % url)
print("Plain md5:\t%s" % md5.new(response.read()).hexdigest())
print("Image md5:\t%s" % md5.new(img_md5).hexdigest())
应该返回这两个系统上相同的MD5哈希值。 我的结果:
的Windows 7:
VERSION 1.1.7
URL: https://i.imgur.com/Mx6NQwM.jpg
Plain md5: 4aacd5b92575ffca6d0ab884f95cc1f9
Image md5: 10eaf568f4d9d33c722ea702fc4d1025
URL: https://i.imgur.com/MN1TKu5.png
Plain md5: d05e6dc1311339b806e5998f15fc818c
Image md5: 38fc986c5cd9605038ee627b11687344
Debian的杰西:
VERSION 1.1.7
URL: https://i.imgur.com/Mx6NQwM.jpg
Plain md5: 4aacd5b92575ffca6d0ab884f95cc1f9
Image md5: 7347c6286f4d917649d967a5025e392e
URL: https://i.imgur.com/MN1TKu5.png
Plain md5: d05e6dc1311339b806e5998f15fc818c
Image md5: 38fc986c5cd9605038ee627b11687344
的LSHS有些相似,但足以为不同它是有问题的。
这两个系统上的枕头版本是2.9.0。
有什么方法可以在debian系统上获得相同的像素值,就像我在windows上得到的那样?
而且一般来说:有人知道为什么会发生这种情况吗?
只是为了确保枕头在两个系统上正确处理jpeg文件,您是否尝试在两个系统上显示数据或将其转换为png,然后计算md5? –
@SteveBarnes刚刚尝试过,图像看起来正确,并且转换为png返回了预期结果(第一张图像不同,第二张图像也一样) – SleepProgger