Create a Pillow Image from the Pixmap.
(self)
| 13736 | return bio.getvalue() |
| 13737 | |
| 13738 | def pil_image(self): |
| 13739 | """Create a Pillow Image from the Pixmap.""" |
| 13740 | try: |
| 13741 | from PIL import Image |
| 13742 | except ImportError: |
| 13743 | message("PIL/Pillow not installed") |
| 13744 | raise |
| 13745 | |
| 13746 | cspace = self.colorspace |
| 13747 | if not cspace: |
| 13748 | mode = "L" |
| 13749 | elif cspace.n == 1: |
| 13750 | mode = "L" if not self.alpha else "LA" |
| 13751 | elif cspace.n == 3: |
| 13752 | mode = "RGB" if not self.alpha else "RGBA" |
| 13753 | else: |
| 13754 | mode = "CMYK" |
| 13755 | |
| 13756 | img = Image.frombytes(mode, (self.width, self.height), self.samples) |
| 13757 | return img |
| 13758 | |
| 13759 | def pil_save(self, *args, **kwargs): |
| 13760 | """Write to image file using Pillow. |
no test coverage detected