read the (width, height) from a JPEG header
(data)
| 806 | |
| 807 | |
| 808 | def _jpegxy(data): |
| 809 | """read the (width, height) from a JPEG header""" |
| 810 | # adapted from http://www.64lines.com/jpeg-width-height |
| 811 | |
| 812 | idx = 4 |
| 813 | while True: |
| 814 | block_size = struct.unpack('>H', data[idx:idx+2])[0] |
| 815 | idx = idx + block_size |
| 816 | if data[idx:idx+2] == b'\xFF\xC0': |
| 817 | # found Start of Frame |
| 818 | iSOF = idx |
| 819 | break |
| 820 | else: |
| 821 | # read another block |
| 822 | idx += 2 |
| 823 | |
| 824 | h, w = struct.unpack('>HH', data[iSOF+5:iSOF+9]) |
| 825 | return w, h |
| 826 | |
| 827 | |
| 828 | def _gifxy(data): |
no outgoing calls
no test coverage detected
searching dependent graphs…