'Updates the width and height fields of the tiff image.
Raises:
BadImageError if the image string is not a valid tiff image.'

def _update_tiff_dimensions(self):

    size = len(self._image_data)
    if self._image_data.startswith('II'):
        endianness = '<'
    else:
        endianness = '>'
    ifd_offset = struct.unpack((endianness + 'I'), self._image_data[4:8])[0]
    if ((ifd_offset + 14) <= size):
        ifd_size = struct.unpack((endianness + 'H'), self._image_data[ifd_offset:(ifd_offset + 2)])[0]
        ifd_offset += 2
        for unused_i in range(0, ifd_size):
            if ((ifd_offset + 12) <= size):
                tag = struct.unpack((endianness + 'H'), self._image_data[ifd_offset:(ifd_offset + 2)])[0]
                if ((tag == 256) or (tag == 257)):
                    value_type = struct.unpack((endianness + 'H'), self._image_data[(ifd_offset + 2):(ifd_offset + 4)])[0]
                    if (value_type == 3):
                        format = (endianness + 'H')
                        end_offset = (ifd_offset + 10)
                    elif (value_type == 4):
                        format = (endianness + 'I')
                        end_offset = (ifd_offset + 12)
                    else:
                        format = (endianness + 'B')
                        end_offset = (ifd_offset + 9)
                    if (tag == 256):
                        self._width = struct.unpack(format, self._image_data[(ifd_offset + 8):end_offset])[0]
                        if (self._height is not None):
                            break
                    else:
                        self._height = struct.unpack(format, self._image_data[(ifd_offset + 8):end_offset])[0]
                        if (self._width is not None):
                            break
                ifd_offset += 12
            else:
                raise BadImageError('Corrupt    TIFF    format')
    if ((self._width is None) or (self._height is None)):
        raise BadImageError('Corrupt    TIFF    format')
