'Transforms this image.  This method creates a new image with the
given size, and the same mode as the original, and copies data
to the new image using the given transform.
:param size: The output size.
:param method: The transformation method.  This is one of
:py:attr:`PIL.Image.EXTENT` (cut out a rectangular subregion),
:py:attr:`PIL.Image.AFFINE` (affine transform),
:py:attr:`PIL.Image.PERSPECTIVE` (perspective transform),
:py:attr:`PIL.Image.QUAD` (map a quadrilateral to a rectangle), or
:py:attr:`PIL.Image.MESH` (map a number of source quadrilaterals
in one operation).
:param data: Extra data to the transformation method.
:param resample: Optional resampling filter.  It can be one of
:py:attr:`PIL.Image.NEAREST` (use nearest neighbour),
:py:attr:`PIL.Image.BILINEAR` (linear interpolation in a 2x2
environment), or :py:attr:`PIL.Image.BICUBIC` (cubic spline
interpolation in a 4x4 environment). If omitted, or if the image
has mode "1" or "P", it is set to :py:attr:`PIL.Image.NEAREST`.
:returns: An :py:class:`~PIL.Image.Image` object.'

def transform(self, size, method, data=None, resample=NEAREST, fill=1):

    if (self.mode == 'LA'):
        return self.convert('La').transform(size, method, data, resample, fill).convert('LA')
    if (self.mode == 'RGBA'):
        return self.convert('RGBa').transform(size, method, data, resample, fill).convert('RGBA')
    if isinstance(method, ImageTransformHandler):
        return method.transform(size, self, resample=resample, fill=fill)
    if hasattr(method, 'getdata'):
        (method, data) = method.getdata()
    if (data is None):
        raise ValueError('missing    method    data')
    im = new(self.mode, size, None)
    if (method == MESH):
        for (box, quad) in data:
            im.__transformer(box, self, QUAD, quad, resample, fill)
    else:
        im.__transformer(((0, 0) + size), self, method, data, resample, fill)
    return im
