Python Forum
understanding output of bytes/raw data - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: understanding output of bytes/raw data (/thread-20215.html)



understanding output of bytes/raw data - rootVIII - Aug-01-2019

I can see that the output of this has some interesting info... such as Created With Gimp Big Grin How can I extract useful information out of s[6]? Or is that just the image data itself? What do the 0th-5th elements represent?



import struct
from requests import get


struct_fmt = '=5if255s'
struct_len = struct.calcsize(struct_fmt)
struct_unpack = struct.Struct(struct_fmt).unpack_from
url_img = 'https://www.restwords.com/static/ICON.png'
# print(struct_unpack(get(url_img).content))
s = struct_unpack(get(url_img).content)
print(s)
edit: here's what the output looks like:

(1196314761, 169478669, 218103808, 1380206665, 1912602624, 2.535301200456459e+30, b'\x08\x02\x00\x00\x00\x00\xbf\x12*\x00\x00\x00\tpHYs\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a\x9c\x18\x00\x00\x00\x07tIME\x07\xe1\t\x01\x0b\x12 \xeb\xaf\xd8i\x00\x00\x00\x19tEXtComment\x00Created with GIMPW\x81\x0e\x17\x00\x00\x00\x06bKGD\x00\xff\x00\xff\x00\xff\xa0\xbd\xa7\x93\x00\x00\x1d\x8cIDATx\xda\xed]\tX\x8di\xfb\x7f\xf7};\xed\xda7[\n\x91\xa5E\xb6\xc1XC\x12\x91"\xb2\x84"\x8d\xa5\x88,1v\t\x83\xa1Bv#\x94\xad\x184*r\xea\x98\xe5\xfb\xbe\x99o\x86\xebb\x98\x19\xe3\xfbf|\x98\xc1\x98\xff\xffy:iB\xa7\xe5tZ\x18\xe7z.\xd7\xd1\xe9<\xbd\xef\xef\xb9\x9f\xfb\xf9\xdd\xeb\x8b\xfc_\x1d\xbc\xee\xdd\xbbW\\\\\x9c}\xf6lNv\xf6W_}\xf5\xc3\x0f?<y\xf2D\xef\xd9\x9e={\x06\xbe\xfe\xf4\xe9S\xf0\xe6\xf9\xf3\xe7\x7f\xfe\xf9')



RE: understanding output of bytes/raw data - fishhook - Aug-01-2019

maybe this information would help you


RE: understanding output of bytes/raw data - Gribouillis - Aug-01-2019

For such a problem, I would look into pypi to find packages related to png or to metadata. For example you have this package ipng. In the source code there are interesting considerations about the contents of the png format and you see that zlib.decompress() is involved in retrieving the metadata.


RE: understanding output of bytes/raw data - rootVIII - Aug-01-2019

both great answers thank you