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

def _update_png_dimensions(self):

    size = len(self._image_data)
    if ((size >= 24) and (self._image_data[12:16] == 'IHDR')):
        (self._width, self._height) = struct.unpack('>II', self._image_data[16:24])
    else:
        raise BadImageError('Corrupt    PNG    format')
