'Return image as a bytes object.
.. warning::
This method returns the raw image data from the internal
storage.  For compressed image data (e.g. PNG, JPEG) use
:meth:`~.save`, with a BytesIO parameter for in-memory
data.
:param encoder_name: What encoder to use.  The default is to
use the standard "raw" encoder.
:param args: Extra arguments to the encoder.
:rtype: A bytes object.'

def tobytes(self, encoder_name='raw', *args):

    if ((len(args) == 1) and isinstance(args[0], tuple)):
        args = args[0]
    if ((encoder_name == 'raw') and (args == ())):
        args = self.mode
    self.load()
    e = _getencoder(self.mode, encoder_name, args)
    e.setimage(self.im)
    bufsize = max(65536, (self.size[0] * 4))
    data = []
    while True:
        (l, s, d) = e.encode(bufsize)
        data.append(d)
        if s:
            break
    if (s < 0):
        raise RuntimeError(('encoder    error    %d    in    tobytes' % s))
    return ''.join(data)
