File: test_imagemasks.py

package info (click to toggle)
pymupdf 1.25.4%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 98,632 kB
  • sloc: python: 43,379; ansic: 75; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 780 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Confirm image mask detection in TextPage extractions. 
"""

import os

import pymupdf

scriptdir = os.path.abspath(os.path.dirname(__file__))
filename1 = os.path.join(scriptdir, "resources", "img-regular.pdf")
filename2 = os.path.join(scriptdir, "resources", "img-transparent.pdf")


def test_imagemask1():
    doc = pymupdf.open(filename1)
    page = doc[0]
    blocks = page.get_text("dict")["blocks"]
    img = blocks[0]
    assert img["mask"] is None
    img = page.get_image_info()[0]
    assert img["has-mask"] is False


def test_imagemask2():
    doc = pymupdf.open(filename2)
    page = doc[0]
    blocks = page.get_text("dict")["blocks"]
    img = blocks[0]
    assert type(img["mask"]) is bytes
    img = page.get_image_info()[0]
    assert img["has-mask"] is True