def _background(self, fmt, color): if self._skip_background: return img = PIL.Image.new(mode="RGBA", size=self.img.size, color=color) if self.img.mode == "RGBA" and Image._supports_alpha(fmt): self.img = PIL.Image.alpha_composite(img, self.img) else: bands = self.img.split() mask = bands[3] if len(bands) == 4 else None img.paste(self.img, mask=mask) self.img = img