除了这一句之外上面应该还有一句:Not a JPEG file: starts with 0x47 0x49
starts with 0x47 0x49说明这是一张gif图像,starts with ffd8说明这是一张jpg图像,其他格式的开头可以看:https://en.wikipedia.org/wiki/List_of_file_signatures
怎么找到这张图呢:
import binascii
image_path = "../data/TB2Ibf9aRLN8KJjSZPhXXc.spXa_!!387492340.gif.jpg"
with open (image_path, "rb") as myfile:
header=myfile.read(24)
header = str(binascii.hexlify(header))[2:-1]
print (header)
##'47494638396120032003f700000000000000330000660000'
另外就是利用PIL来判断是否是jpg格式:
from PIL import Image
def is_jpg(filename):
try:
i=Image.open(filename)
return i.format =='JPEG'
except IOError:
return Fals
备注:
decode_gif(...)
: 将GIF编码图像的第一帧解码为 uint8 tensor。
decode_image(...)
: 图像解码操作,包含了 decode_gif, decode_jpeg,和 decode_png。
decode_jpeg(...)
: 将jpeg编码图像解码为 uint8 tensor。
decode_png(...)
: 将png编码图像解码为 uint16 tensor。