Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fitz.Pixmap(None, pix) Unrecognised args for constructing Pixmap #3177

Closed
luhuaei opened this issue Feb 18, 2024 · 4 comments
Closed

fitz.Pixmap(None, pix) Unrecognised args for constructing Pixmap #3177

luhuaei opened this issue Feb 18, 2024 · 4 comments

Comments

@luhuaei
Copy link
Contributor

luhuaei commented Feb 18, 2024

Description of the bug

    pixalpha = fitz.Pixmap(None, pixmap)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/fitz/__init__.py", line 9723, in __init__
    raise Exception( text)
Exception: Unrecognised args for constructing Pixmap:
    <class 'NoneType'>: None
    <class 'fitz.Pixmap'>: Pixmap(DeviceRGB, (0, 0, 1920, 2485), 1)

How to reproduce the bug

read the document

>>> import fitz
>>> pix = fitz.Pixmap("screenshot.png")
>>> pix
Pixmap(DeviceRGB, (0, 0, 3840, 2400), 1)
>>> alpha = fitz.Pixmap(None, pix)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.11/site-packages/fitz/__init__.py", line 9723, in __init__
    raise Exception( text)
Exception: Unrecognised args for constructing Pixmap:
    <class 'NoneType'>: None
    <class 'fitz.Pixmap'>: Pixmap(DeviceRGB, (0, 0, 3840, 2400), 1)

>>> fitz.version 
('1.23.22', '1.23.10', '20240212000001')
>>> 

PyMuPDF version

1.23.22

Operating system

Linux

Python version

3.11

@julian-smith-artifex-com
Copy link
Collaborator

Thanks for reporting this. I have a fix in my tree, so hopefully it'll be in the next release in a few days time.

@julian-smith-artifex-com
Copy link
Collaborator

Fixed in 1.23.23.

@luhuaei
Copy link
Contributor Author

luhuaei commented Feb 19, 2024

Thanks!

@jack-gits
Copy link

when I extract the images from PDF, it still raise errors as following.

`doc = fitz.open(file)
docs=[]
b_unit = tqdm.tqdm(total=doc.page_count, desc="PDFOCRReader context page index: 0")
for i, page in enumerate(doc):

        # 更新描述
        b_unit.set_description("PDFOCRReader context page index: {}".format(i))
        # 立即显示进度条更新结果
        b_unit.refresh()
        # TODO: 依据文本与图片顺序调整处理方式
        text = page.get_text("")
        resp = text + "\n"

        img_list = page.get_images()
        for img in img_list:
            try:
                pix = fitz.Pixmap(doc, img[0])
                
            except Exception as e:

                # otherwise, just skip the file and report the error
                print(
                    f"Failed to load file {file} with error: {e}. Skipping...",
                    flush=True,
                )`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants