comparison tests/test_imagebbox.py @ 1:1d09e1dec1d9 upstream

ADD: PyMuPDF v1.26.4: the original sdist. It does not yet contain MuPDF. This normally will be downloaded when building PyMuPDF.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:37:51 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 1:1d09e1dec1d9
1 """
2 Ensure equality of bboxes computed via
3 * page.get_image_bbox()
4 * page.get_image_info()
5 * page.get_bboxlog()
6
7 """
8 import os
9
10 import pymupdf
11
12 scriptdir = os.path.abspath(os.path.dirname(__file__))
13 filename = os.path.join(scriptdir, "resources", "image-file1.pdf")
14 image = os.path.join(scriptdir, "resources", "img-transparent.png")
15 doc = pymupdf.open(filename)
16
17
18 def test_image_bbox():
19 page = doc[0]
20 imglist = page.get_images(True)
21 bbox_list = []
22 for item in imglist:
23 bbox_list.append(page.get_image_bbox(item, transform=False))
24 infos = page.get_image_info(xrefs=True)
25 match = False
26 for im in infos:
27 bbox1 = im["bbox"]
28 match = False
29 for bbox2 in bbox_list:
30 abs_bbox = (bbox2 - bbox1).norm()
31 if abs_bbox < 1e-4:
32 match = True
33 break
34 assert match
35
36
37 def test_bboxlog():
38 doc = pymupdf.open()
39 page = doc.new_page()
40 xref = page.insert_image(page.rect, filename=image)
41 img_info = page.get_image_info(xrefs=True)
42 assert len(img_info) == 1
43 info = img_info[0]
44 assert info["xref"] == xref
45 bbox_log = page.get_bboxlog()
46 assert len(bbox_log) == 1
47 box_type, bbox = bbox_log[0]
48 assert box_type == "fill-image"
49 assert bbox == info["bbox"]