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

Function get_image_rects

src_classic/utils.py:724–758  ·  view source on GitHub ↗

Return list of image positions on a page. Args: name: (str, list, int) image identification. May be reference name, an item of the page's image list or an xref. transform: (bool) whether to also return the transformation matrix. Returns: A list of Rect

(page: Page, name, transform=False)

Source from the content-addressed store, hash-verified

722
723
724def get_image_rects(page: Page, name, transform=False) -> list:
725 """Return list of image positions on a page.
726
727 Args:
728 name: (str, list, int) image identification. May be reference name, an
729 item of the page's image list or an xref.
730 transform: (bool) whether to also return the transformation matrix.
731 Returns:
732 A list of Rect objects or tuples of (Rect, Matrix) for all image
733 locations on the page.
734 """
735 if type(name) in (list, tuple):
736 xref = name[0]
737 elif type(name) is int:
738 xref = name
739 else:
740 imglist = [i for i in page.get_images() if i[7] == name]
741 if imglist == []:
742 raise ValueError("bad image name")
743 elif len(imglist) != 1:
744 raise ValueError("multiple image names found")
745 xref = imglist[0][0]
746 pix = Pixmap(page.parent, xref) # make pixmap of the image to compute MD5
747 digest = pix.digest
748 del pix
749 infos = page.get_image_info(hashes=True)
750 if not transform:
751 bboxes = [Rect(im["bbox"]) for im in infos if im["digest"] == digest]
752 else:
753 bboxes = [
754 (Rect(im["bbox"]), Matrix(im["transform"]))
755 for im in infos
756 if im["digest"] == digest
757 ]
758 return bboxes
759
760
761def get_text(

Callers

nothing calls this directly

Calls 5

PixmapClass · 0.85
RectClass · 0.85
MatrixClass · 0.85
get_imagesMethod · 0.80
get_image_infoMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…