-
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
Exception in insert_image with mask specified #3087
Comments
I have changed the unusable title of this post to something more meaningful. |
Confirming the problem. |
@JorjMcKie I am trying to not use pixmap if possible, because it seems to increase file size, and reduce image quality for raster images. Am I incorrect about this? |
Larger file sizes can be coped with by using proper |
src/__init__.py: Page._insert_image(): avoid problems caused by mupdf.fz_new_image_from_compressed_buffer() being unusable from Python, due to decode and colorkey args being incorrectly treated as out-params. Also avoid double free of fz_compressed_buffer due to not being ref-counted, but used by two images. The fix follows classic, and probably results in a small memory leak. src/extra.i: Added fz_new_image_from_compressed_buffer(), wrapper for mupdf::fz_new_image_from_compressed_buffer(), without problematic decode and colorkey args. tests/test_insertimage.py: Added test_3087(). tests/resources/test_3087.pdf: New, for use by test_3087().
src/__init__.py: Page._insert_image(): avoid problems caused by mupdf.fz_new_image_from_compressed_buffer() being unusable from Python, due to decode and colorkey args being incorrectly treated as out-params. Also avoid double free of fz_compressed_buffer due to not being ref-counted, but used by two images. The fix follows classic, and probably results in a small memory leak. src/extra.i: Added fz_new_image_from_compressed_buffer(), wrapper for mupdf::fz_new_image_from_compressed_buffer(), without problematic decode and colorkey args. tests/test_insertimage.py: Added test_3087(). tests/resources/test_3087.pdf: New, for use by test_3087().
src/__init__.py: Page._insert_image(): avoid problems caused by mupdf.fz_new_image_from_compressed_buffer() being unusable from Python, due to decode and colorkey args being incorrectly treated as out-params. Also avoid double free of fz_compressed_buffer due to not being ref-counted, but used by two images. The fix follows classic, and probably results in a small memory leak. src/extra.i: Added fz_new_image_from_compressed_buffer(), wrapper for mupdf::fz_new_image_from_compressed_buffer(), without problematic decode and colorkey args. tests/test_insertimage.py: Added test_3087(). tests/resources/test_3087.pdf: New, for use by test_3087().
Fixed in 1.23.19. |
Description of the bug
This is the code block that produces the error:
create new page
width, height = page.mediabox_size
new_page = new_pdf.new_page(width=width, height=height)
get bounding box info and extract the position of the images
page_bounding_box_info = doc[index].get_bboxlog()
image_bounding_box_info = []
for bbx in page_bounding_box_info:
if(bbx[0] == 'fill-image'):
image_bounding_box_info.append(bbx[1])
insert these images into the new page
for index, bbx in enumerate(image_bounding_box_info):
positional_info = bbx
Error happens on this line:
new_page.insert_image(positional_info, stream=image_bytes, mask=smask_pil)
Error happens in PyMuPDF/src/init.py
zimg = mupdf.fz_new_image_from_compressed_buffer(
w, h,
bpc, colorspace, xres, yres, 1, 0, None,
None, cbuf1, mask
)
How to reproduce the bug
Traceback (most recent call last): File "C:\Users\{user}\Desktop\{my_file}.py", line 375, in extract_image_from_pdf new_image_xref = new_page.insert_image(positional_info, stream=image_bytes, mask=smask_pil) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\{user}\AppData\Local\Programs\Python\Python311\Lib\site-packages\fitz\utils.py", line 364, in insert_image xref, digests = page._insert_image( ^^^^^^^^^^^^^^^^^^^ File "C:\Users\{user}\AppData\Local\Programs\Python\Python311\Lib\site-packages\fitz\__init__.py", line 7823, in _insert_image zimg = mupdf.fz_new_image_from_compressed_buffer( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: fz_new_image_from_compressed_buffer_outparams_fn() takes 10 positional arguments but 12 were given Failed to extract image(s) from page, ran into error fz_new_image_from_compressed_buffer_outparams_fn() takes 10 positional arguments but 12 were given
PyMuPDF version
1.23.15
Operating system
Windows
Python version
3.11
The text was updated successfully, but these errors were encountered: