Returns np_image encoded as jpeg or png.

def _encode_image(self, np_image):
    """Returns np_image encoded as jpeg or png."""
    if np_image.dtype != np.uint8:
      raise ValueError('Image should be uint8. Detected: %s.' % np_image.dtype)
    utils.assert_shape_match(np_image.shape, self._shape)
    return self._runner.run(ENCODE_FN[self._encoding_format], np_image)