-
Notifications
You must be signed in to change notification settings - Fork 510
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 x- and y-coordinate are immutable #645
Comments
Related to this, the documentation for Pixmap.copyPixmap includes this text:
This suggests the intent is consistent with the recipe code that the x- and y-coordinate of a Pixmap should be settable. |
Correct - thanks for reporting this. |
No urgency at all. Thanks for your work on this. |
New version 1.17.7 addresses this and is being uploaded right now. |
I updated to 1.17.7 with
|
Weird, here is my snippet: >>> import fitz
>>> print(fitz.__doc__)
PyMuPDF 1.17.7: Python bindings for the MuPDF 1.17.0 library.
Version date: 2020-09-14 06:33:06.
Built for Python 3.7 on win32 (64-bit).
>>> pix=fitz.Pixmap("page8.png")
>>> pix
Pixmap(DeviceRGB, IRect(0, 0, 596, 794), 0)
>>> pix.setOrigin(5, 5)
>>> pix
Pixmap(DeviceRGB, IRect(5, 5, 601, 799), 0)
>>> |
The attributes pix.x, pix.y can indeed not be changed directly - that hasn't changed ... |
import fitz
src = fitz.Pixmap('img-7edges.png') # create pixmap from a picture
col = 3 # tiles per row
lin = 4 # tiles per column
tar_w = src.width * col # width of target
tar_h = src.height * lin # height of target
# create target pixmap
tar_pix = fitz.Pixmap(src.colorspace, (0, 0, tar_w, tar_h), src.alpha)
# now fill target with the tiles
for i in range(col):
for j in range(lin):
src.setOrigin(src.width * i, src.height * j)
tar_pix.copyPixmap(src, src.irect) # copy input to new loc
tar_pix.writePNG('tar.png') Thank you for your help with this. |
Description of the bug
This might be a documentation bug rather than a functional one. I need to copy a region of a source Pixmap to a destination Pixmap. The recipe for doing so does not work as written.
To Reproduce
The recipe code fails at this line:
src.x = src.width * i # modify input's x coord
...with the error:
AttributeError: can't set attribute
Expected behavior
If the x and y coordinates of a Pixmap are intended to be mutable, this is a functional bug and the expected behavior would be as shown in the recipe.
If the x and y coordinates of a Pixmap are intended to be immutable, some documentation of the current best practice for copying a portion of one Pixmap to another would be welcomed. For example, is it necessary to apply a translation Matrix to the source Pixmap before copying, or is there a better way?
My configuration
PyMuPDF was installed with a wheel using
pip install PyMuPDF
The text was updated successfully, but these errors were encountered: