It should be enuff to test for
Start bits:
b'\xff\xd8\xff'
,then it's a jpg.Start bits:
$JPEG = "\xFF\xD8\xFF" $GIF = "GIF" $PNG = "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" $BMP = "BM" $PSD = "8BPS" $SWF = "FWS"
with open('some.gif', 'rb') as fd: file_head = fd.read(3) print(file_head)
Output:b'GIF'
atux_nul Wrote:and 255, 216, 255 in integers
>>> s b'\xff\xd8\xff' >>> [i for i in s] [255, 216, 255]You see on wiki page that it decode to
ÿØÿÛ
using ISO 8859-1.>>> s b'\xff\xd8\xff' >>> s.decode('iso-8859-1') 'ÿØÿ'