Created
August 4, 2018 04:53
-
-
Save GiantRobato/6a97879085a26c6e2819e8054f44ce07 to your computer and use it in GitHub Desktop.
reads a 1 pixel png file as a binary file and looks at the data contained inside
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import struct | |
import zlib | |
with open('./whitePixel.png','rb') as f: | |
PNGheader = f.read(8) | |
while True: | |
chunk = f.read(4) | |
if not chunk: break | |
chunkType = f.read(4) | |
numBytes = int.from_bytes(chunk, byteorder='big') | |
data = f.read(numBytes) | |
crc = f.read(4) | |
try: | |
chunkType = bytes(chunkType).decode('utf-8') | |
if chunkType == 'IDAT': | |
deflated = zlib.decompress(data) | |
(a,r,g,b) = struct.unpack('<BBBB',deflated) | |
print('argb value is: [{},{},{},{}]'.format(a,r,g,b)) | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment