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:
(page: 'Page', name, transform=False)
| 11736 | return imginfo |
| 11737 | |
| 11738 | def get_image_rects(page: 'Page', name, transform=False) -> list: |
| 11739 | """Return list of image positions on a page. |
| 11740 | |
| 11741 | Args: |
| 11742 | name: (str, list, int) image identification. May be reference name, an |
| 11743 | item of the page's image list or an xref. |
| 11744 | transform: (bool) whether to also return the transformation matrix. |
| 11745 | Returns: |
| 11746 | A list of pymupdf.Rect objects or tuples of (pymupdf.Rect, pymupdf.Matrix) |
| 11747 | for all image locations on the page. |
| 11748 | """ |
| 11749 | if type(name) in (list, tuple): |
| 11750 | xref = name[0] |
| 11751 | elif type(name) is int: |
| 11752 | xref = name |
| 11753 | else: |
| 11754 | imglist = [i for i in page.get_images() if i[7] == name] |
| 11755 | if imglist == []: |
| 11756 | raise ValueError("bad image name") |
| 11757 | elif len(imglist) != 1: |
| 11758 | raise ValueError("multiple image names found") |
| 11759 | xref = imglist[0][0] |
| 11760 | pix = Pixmap(page.parent, xref) # make pixmap of the image to compute MD5 |
| 11761 | digest = pix.digest |
| 11762 | del pix |
| 11763 | infos = page.get_image_info(hashes=True) |
| 11764 | if not transform: |
| 11765 | bboxes = [Rect(im["bbox"]) for im in infos if im["digest"] == digest] |
| 11766 | else: |
| 11767 | bboxes = [ |
| 11768 | (Rect(im["bbox"]), Matrix(im["transform"])) |
| 11769 | for im in infos |
| 11770 | if im["digest"] == digest |
| 11771 | ] |
| 11772 | return bboxes |
| 11773 | |
| 11774 | def get_label(page): |
| 11775 | """Return the label for this PDF page. |