

def _size_from_jpeg(img_data):
    'A very crude JPEG reader so that we can get the image size'
    pos = 0
    if ((ord(img_data[pos]) != 255) or (ord(img_data[(pos + 1)]) != 216)):
        _debug(('SOI not found %u %u' % (ord(img_data[pos]), ord(img_data[(pos + 1)]))))
        return None
    pos += 2
    sos = False
    while (not sos):
        if (ord(img_data[pos]) != 255):
            _debug(('marker not found at pos %d' % pos))
            return None
        if (ord(img_data[(pos + 1)]) == 192):
            sos = True
            pos += 2
        else:
            pos += 2
            len = _read_2byte(img_data, pos)
            _debug(('len %d' % len))
            pos += len
    pos += 3
    _debug(('h %x %x' % (ord(img_data[pos]), ord(img_data[(pos + 1)]))))
    height = _read_2byte(img_data, pos)
    pos += 2
    width = _read_2byte(img_data, pos)
    return (width, height)

dataset/ETHPy150Open CollabQ/CollabQ/common/imageutil.py _size_from_jpeg/original