python 16进制与图片互转
import binascii
# payload为十六进制字符串,如:“ffd8ffe111e0457869...”;经过如下代码转换,可将pic存储为图片形式并可以正常打开
f=open("1.png","ab") # filepath为你要存储的图片的全路径
pic = binascii.a2b_hex(payload.encode())
f.write(pic)
f.close()
import binascii
filename = './zeh.jpg'
with open(filename, 'rb') as f:
content = f.read()
print(binascii.hexlify(content))
with open("aaa.txt", 'a') as f:
f.write(str(binascii.hexlify(content)))