MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / pil_image

Method pil_image

src/__init__.py:13738–13757  ·  view source on GitHub ↗

Create a Pillow Image from the Pixmap.

(self)

Source from the content-addressed store, hash-verified

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.

Callers 2

pil_saveMethod · 0.95
pil_tobytesMethod · 0.95

Calls 1

messageFunction · 0.70

Tested by

no test coverage detected