Skip to content

Instantly share code, notes, and snippets.

@theredpea
Created June 27, 2014 01:09
Show Gist options
  • Save theredpea/7d8e30f6716dd134e7be to your computer and use it in GitHub Desktop.
Save theredpea/7d8e30f6716dd134e7be to your computer and use it in GitHub Desktop.
filepath = r'\\path\to\file\may\not\be\a\PNG.png'
filepath.replace('\\', '/')
f = open(filepath, mode='b')
b = f.read(8)
for _ in b:
print (_)
print (hex(_))
#Notice the first two hex values are 42 and 4d;
#Consistent with BMP filetype (despite the extension),
#As shown here: http://yazeem.wordpress.com/2009/10/25/determine-image-file-type-using-its-header/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment