read the (width, height) from a JPEG header
(data)
| 1069 | return struct.unpack('>ii', data[ihdr+4:ihdr+12]) |
| 1070 | |
| 1071 | def _jpegxy(data): |
| 1072 | """read the (width, height) from a JPEG header""" |
| 1073 | # adapted from http://www.64lines.com/jpeg-width-height |
| 1074 | |
| 1075 | idx = 4 |
| 1076 | while True: |
| 1077 | block_size = struct.unpack('>H', data[idx:idx+2])[0] |
| 1078 | idx = idx + block_size |
| 1079 | if data[idx:idx+2] == b'\xFF\xC0': |
| 1080 | # found Start of Frame |
| 1081 | iSOF = idx |
| 1082 | break |
| 1083 | else: |
| 1084 | # read another block |
| 1085 | idx += 2 |
| 1086 | |
| 1087 | h, w = struct.unpack('>HH', data[iSOF+5:iSOF+9]) |
| 1088 | return w, h |
| 1089 | |
| 1090 | def _gifxy(data): |
| 1091 | """read the (width, height) from a GIF header""" |