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

1.17.6: insertImage: rect cannot be a list #622

Closed
cbm755 opened this issue Aug 27, 2020 · 8 comments
Closed

1.17.6: insertImage: rect cannot be a list #622

cbm755 opened this issue Aug 27, 2020 · 8 comments
Assignees
Labels

Comments

@cbm755
Copy link
Contributor

cbm755 commented Aug 27, 2020

On upgrade to 1.17.6, I started getting:

         pg.insertImage(rec, filename=img)
       File "/usr/local/lib/python3.6/dist-packages/fitz/utils.py", line 290, in insertImage
         if r.isEmpty or r.isInfinite:
     AttributeError: 'list' object has no attribute 'isEmpty'

configuration

  • GNU/Linux, Ubuntu 18.04, Fedora 32, several machines
  • Python 3.6 and 3.8 (so far)
  • PyMuPDF 1.17.6 from pip (via wheel I suppose)
3.8.5 (default, Aug 12 2020, 00:00:00) 
[GCC 10.2.1 20200723 (Red Hat 10.2.1-1)] 
 linux 
 
PyMuPDF 1.17.6: Python bindings for the MuPDF 1.17.0 library.
Version date: 2020-08-26 14:54:32.
Built for Python 3.8 on linux (64-bit).

Minimal example:

doc = fitz.open()
pg = exam.newPage()
rec = [10, 10, 90, 80]
pg.insertImage(rec, filename="image.png")                 
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-7970f4ceb718> in <module>
----> 1 pg.insertImage(rec, filename="target_Q_latex_plom.png")

~/.local/lib/python3.8/site-packages/fitz/utils.py in insertImage(page, rect, filename, pixmap, stream, rotate, keep_proportion, overlay)
    288 
    289     r = rect
--> 290     if r.isEmpty or r.isInfinite:
    291         raise ValueError("rect must be finite and not empty")
    292 

AttributeError: 'list' object has no attribute 'isEmpty'
@cbm755 cbm755 added the bug label Aug 27, 2020
@cbm755 cbm755 changed the title 1.17.6: cannot insert image into page 1.17.6: insertImage: rect cannot be a list Aug 27, 2020
@cbm755
Copy link
Contributor Author

cbm755 commented Aug 27, 2020

I guess I'm not allowed to pass a list for rect... Was I ever allowed to?

This works:

pg.insertImage(fitz.Rect(rec), filename="image.png")

@JorjMcKie
Copy link
Collaborator

I guess I'm not allowed to pass a list for rect... Was I ever allowed to?

Yes, you ought to be!
I probably unintentionally removed some Fitz.Rect conversion along the way - sorry about that.

cbm755 added a commit to plomgrading/plom that referenced this issue Aug 27, 2020
This is a workaround for pymupdf/PyMuPDF#622
which may not even by a bug b/c in other places we use `fitz.Rect`.  So
its certainly not wrong to use `fitz.Rect` explicitly!
@cbm755
Copy link
Contributor Author

cbm755 commented Aug 27, 2020

Thanks! Docs say rect-like [1]: I guess I interpreted that a bit too loosely!

Actually in most places my co-author had uses fitz.Rect explicitly so probably just my confusion. Feel free to close.

[1] update: by "docs" I mean docstring of pg.insertImage

@JorjMcKie
Copy link
Collaborator

No, no, it was my bad. The intention is to allow rect-like.
I made a change this time and removed the condition, that the parameter's intersected with CropBox must not be empty. In order to allow image insertion somewhere on the MediaBox even if that place would not be visible in the current CropBox. Also no longer wanted to shrink the image to that intersection - making it possible that a larger image would be visible only partly.
Hope I made myself clear.
And in the course of that forgot to convert the parameter to a rect before testing it ... 🙄

@JorjMcKie
Copy link
Collaborator

@cbm755 - concerning gluing / glueing: my dictionaries tell me that both forms are correct. Which I didn't know either.

@cbm755
Copy link
Contributor Author

cbm755 commented Aug 28, 2020

I see. I put that one as a single separate commit b/c I was unsure so feel free to revert it.

@JorjMcKie
Copy link
Collaborator

I put that one as a single separate commit b/c I was unsure so feel free to revert it.

Never mind, really. I am glad you have been looking through major parts of the docu, again a big thank you for this.

@JorjMcKie
Copy link
Collaborator

New version 1.17.7 addressing this is being uploaded right now.

cbm755 added a commit to plomgrading/plom that referenced this issue Sep 25, 2020
This is a workaround for pymupdf/PyMuPDF#622
which may not even by a bug b/c in other places we use `fitz.Rect`.  So
its certainly not wrong to use `fitz.Rect` explicitly!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants