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

Pixmap resizing needs positional arg "clip" - even if None #3139

Closed
paaguti opened this issue Feb 7, 2024 · 4 comments
Closed

Pixmap resizing needs positional arg "clip" - even if None #3139

paaguti opened this issue Feb 7, 2024 · 4 comments
Labels
enhancement fix developed release schedule to be determined

Comments

@paaguti
Copy link

paaguti commented Feb 7, 2024

Description of the bug

I'm trying to resize a pixmap with

    npixmap = fitz.Pixmap(pixmap, new_width, new_height)

And that throws the following exception

Traceback (most recent call last):
  File "/home/paag/bin/img2pdf", line 129, in <module>
    main()
  File "/home/paag/bin/img2pdf", line 89, in main
    npixmap = fitz.Pixmap(pixmap, new_width, new_height)
  File "/home/paag/.local/lib/python3.10/site-packages/fitz/__init__.py", line 9471, in __init__
    elif args_match(args, (Pixmap, mupdf.FzPixmap), (int, None)):
  File "/home/paag/.local/lib/python3.10/site-packages/fitz/__init__.py", line 17869, in args_match
    if type_ is not None and not isinstance(args[j], type_):
TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

How to reproduce the bug

This is the MWE to reproduce the Exception:

XINCH=8.268
YINCH=11.693
dpi=50
f = 'test.png'
pixmap = fitz.Pixmap(f)
ratio = pixmap.height/pixmap.width
new_width = XINCH * dpi
new_height = new_width * ratio
npixmap = fitz.Pixmap(pixmap, new_width, new_height)

The intent is that npixmap can be included in a 50 dpi A4 pdf

PyMuPDF version

1.23.21

Operating system

Linux

Python version

3.10

@JorjMcKie
Copy link
Collaborator

Your bug report does not refer to the stated PyMuPDF version 1.23.21: the line number 9471 in __init__.py contains different code.

Otherwise, we have a documentation imprecision:
Contrary to the documentation, the call pattern Pixmap(oldpix, newwidth, newheight, None) always requires the last parameter, which may an IRect clip or None.

@JorjMcKie
Copy link
Collaborator

Given this, I will change the function to make the last parameter None/clip optional.
For now, your code should work, if you add None as the last parameter.

@paaguti
Copy link
Author

paaguti commented Feb 7, 2024 via email

@JorjMcKie JorjMcKie changed the title fitz.Pixmap() resizing does not work Pixmap resizing requires positional parm "clip" - even if None Feb 11, 2024
@JorjMcKie JorjMcKie changed the title Pixmap resizing requires positional parm "clip" - even if None Pixmap resizing needs positional arg "clip" - even if None Feb 11, 2024
@JorjMcKie JorjMcKie added the fix developed release schedule to be determined label Feb 11, 2024
@julian-smith-artifex-com
Copy link
Collaborator

Fixed in 1.23.22.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement fix developed release schedule to be determined
Projects
None yet
Development

No branches or pull requests

3 participants