Skip to content

insert_image with mask is broken in latest release #1014

@MerlijnWajer

Description

@MerlijnWajer

Describe the bug (mandatory)

page.insert_image does not work when using a mask any more. It used to work in 1.18.1, but it's broken in 1.18.12.

To Reproduce (mandatory)

$ cat image-mask-test.py
import fitz
import sys
import io

img_fg = sys.argv[1]
img_mask = sys.argv[2]
out = sys.argv[3]

fg_stream = open(img_fg, 'rb').read()
mask_stream = open(img_mask, 'rb').read()

doc = fitz.open()
page = doc.newPage()
#page = doc.new_page()
page.insertImage(page.rect, stream=fg_stream, mask=mask_stream)
#page.insert_image(page.rect, stream=fg_stream, mask=mask_stream)

print('mupdf warnings, if any:', repr(fitz.TOOLS.mupdf_warnings()))

doc.save(out)

Test images found here: https://archive.org/~merlijn/tmp/pymupdf-mask-bug/

1.18.12 has this error and creates a corrupt PDF:

mupdf warnings, if any: 'padding truncated image'

1.18.1 works fine.

Expected behavior (optional)

PDF is created properly, no errors are raised.

Your configuration (mandatory)

  • Linux
  • Python 3.8 Python version, bitness
  • PyMuPDF version 1.18.12, installed via pip (wheel).

For example, the output of print(sys.version, "\n", sys.platform, "\n", fitz.__doc__) would be sufficient (for the first two bullets).

>>> sys.version
'3.8.8 (default, Apr 13 2021, 16:35:22) \n[GCC 9.2.0]'
>>> sys.platform
'linux'
fitz.__doc__
'\nPyMuPDF 1.18.12: Python bindings for the MuPDF 1.18.0 library.\nVersion date: 2021-04-10 04:00:00.\nBuilt for Python 3.8 on linux (64-bit).\n'

Additional context (optional)

I wanted to look into some memory usage issues in my application and also switch my patched mupdf-jbig2 build over to the latest version of pymupdf, but ran into this problem, so installed the pip version and the problem persists (no jbig2 involved).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions