'Adds or replaces the alpha layer in this image.  If the image
does not have an alpha layer, it\'s converted to "LA" or "RGBA".
The new layer must be either "L" or "1".
:param alpha: The new alpha layer.  This can either be an "L" or "1"
image having the same size as this image, or an integer or
other color value.'

def putalpha(self, alpha):

    self.load()
    if self.readonly:
        self._copy()
    if (self.mode not in ('LA', 'RGBA')):
        try:
            mode = (getmodebase(self.mode) + 'A')
            try:
                self.im.setmode(mode)
                self.pyaccess = None
            except (AttributeError, ValueError):
                im = self.im.convert(mode)
                if (im.mode not in ('LA', 'RGBA')):
                    raise ValueError
                self.im = im
                self.pyaccess = None
            self.mode = self.im.mode
        except (KeyError, ValueError):
            raise ValueError('illegal    image    mode')
    if (self.mode == 'LA'):
        band = 1
    else:
        band = 3
    if isImageType(alpha):
        if (alpha.mode not in ('1', 'L')):
            raise ValueError('illegal    image    mode')
        alpha.load()
        if (alpha.mode == '1'):
            alpha = alpha.convert('L')
    else:
        try:
            self.im.fillband(band, alpha)
        except (AttributeError, ValueError):
            alpha = new('L', self.size, alpha)
        else:
            return
    self.im.putband(alpha.im, band)
