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

Function get_pixmap

src_classic/utils.py:879–919  ·  view source on GitHub ↗

Create pixmap of page. Keyword args: matrix: Matrix for transformation (default: Identity). dpi: desired dots per inch. If given, matrix is ignored. colorspace: (str/Colorspace) cmyk, rgb, gray - case ignored, default csRGB. clip: (irect-like) restrict rendering

(
    page: Page,
    *,
    matrix: matrix_like = Identity,
    dpi=None,
    colorspace: Colorspace = csRGB,
    clip: rect_like = None,
    alpha: bool = False,
    annots: bool = True,
)

Source from the content-addressed store, hash-verified

877
878
879def get_pixmap(
880 page: Page,
881 *,
882 matrix: matrix_like = Identity,
883 dpi=None,
884 colorspace: Colorspace = csRGB,
885 clip: rect_like = None,
886 alpha: bool = False,
887 annots: bool = True,
888) -> Pixmap:
889 """Create pixmap of page.
890
891 Keyword args:
892 matrix: Matrix for transformation (default: Identity).
893 dpi: desired dots per inch. If given, matrix is ignored.
894 colorspace: (str/Colorspace) cmyk, rgb, gray - case ignored, default csRGB.
895 clip: (irect-like) restrict rendering to this area.
896 alpha: (bool) whether to include alpha channel
897 annots: (bool) whether to also render annotations
898 """
899 CheckParent(page)
900 if dpi:
901 zoom = dpi / 72
902 matrix = Matrix(zoom, zoom)
903
904 if type(colorspace) is str:
905 if colorspace.upper() == "GRAY":
906 colorspace = csGRAY
907 elif colorspace.upper() == "CMYK":
908 colorspace = csCMYK
909 else:
910 colorspace = csRGB
911 if colorspace.n not in (1, 3, 4):
912 raise ValueError("unsupported colorspace")
913
914 dl = page.get_displaylist(annots=annots)
915 pix = dl.get_pixmap(matrix=matrix, colorspace=colorspace, alpha=alpha, clip=clip)
916 dl = None
917 if dpi:
918 pix.set_dpi(dpi, dpi)
919 return pix
920
921
922def get_page_pixmap(

Callers

nothing calls this directly

Calls 5

CheckParentFunction · 0.85
MatrixClass · 0.85
get_displaylistMethod · 0.80
set_dpiMethod · 0.80
get_pixmapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…