Get rectangle occupied by image 'name'. 'name' is either an item of the image list, or the referencing name string - elem[7] of the resp. item. Option 'transform' also returns the image transformation matrix.
(self, name, transform=0)
| 12015 | return self.parent.get_page_fonts(self.number, full=full) |
| 12016 | |
| 12017 | def get_image_bbox(self, name, transform=0): |
| 12018 | """Get rectangle occupied by image 'name'. |
| 12019 | |
| 12020 | 'name' is either an item of the image list, or the referencing |
| 12021 | name string - elem[7] of the resp. item. |
| 12022 | Option 'transform' also returns the image transformation matrix. |
| 12023 | """ |
| 12024 | CheckParent(self) |
| 12025 | doc = self.parent |
| 12026 | if doc.is_closed or doc.is_encrypted: |
| 12027 | raise ValueError('document closed or encrypted') |
| 12028 | |
| 12029 | inf_rect = Rect(1, 1, -1, -1) |
| 12030 | null_mat = Matrix() |
| 12031 | if transform: |
| 12032 | rc = (inf_rect, null_mat) |
| 12033 | else: |
| 12034 | rc = inf_rect |
| 12035 | |
| 12036 | if type(name) in (list, tuple): |
| 12037 | if not type(name[-1]) is int: |
| 12038 | raise ValueError('need item of full page image list') |
| 12039 | item = name |
| 12040 | else: |
| 12041 | imglist = [i for i in doc.get_page_images(self.number, True) if name == i[7]] |
| 12042 | if len(imglist) == 1: |
| 12043 | item = imglist[0] |
| 12044 | elif imglist == []: |
| 12045 | raise ValueError('bad image name') |
| 12046 | else: |
| 12047 | raise ValueError(f"found multiple images named '{name}'.") |
| 12048 | xref = item[-1] |
| 12049 | if xref != 0 or transform: |
| 12050 | try: |
| 12051 | return self.get_image_rects(item, transform=transform)[0] |
| 12052 | except Exception: |
| 12053 | exception_info() |
| 12054 | return inf_rect |
| 12055 | pdf_page = self._pdf_page() |
| 12056 | val = JM_image_reporter(pdf_page) |
| 12057 | |
| 12058 | if not bool(val): |
| 12059 | return rc |
| 12060 | |
| 12061 | for v in val: |
| 12062 | if v[0] != item[-3]: |
| 12063 | continue |
| 12064 | q = Quad(v[1]) |
| 12065 | bbox = q.rect |
| 12066 | if transform == 0: |
| 12067 | rc = bbox |
| 12068 | break |
| 12069 | |
| 12070 | hm = Matrix(util_hor_matrix(q.ll, q.lr)) |
| 12071 | h = abs(q.ll - q.ul) |
| 12072 | w = abs(q.ur - q.ul) |
| 12073 | m0 = Matrix(1 / w, 0, 0, 1 / h, 0, 0) |
| 12074 | m = ~(hm * m0) |