MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / _insert_image

Method _insert_image

src/__init__.py:9988–10158  ·  view source on GitHub ↗
(self,
            filename=None, pixmap=None, stream=None, imask=None, clip=None,
            overlay=1, rotate=0, keep_proportion=1, oc=0, width=0, height=0,
            xref=0, alpha=-1, _imgname=None, digests=None
            )

Source from the content-addressed store, hash-verified

9986 return tpage
9987
9988 def _insert_image(self,
9989 filename=None, pixmap=None, stream=None, imask=None, clip=None,
9990 overlay=1, rotate=0, keep_proportion=1, oc=0, width=0, height=0,
9991 xref=0, alpha=-1, _imgname=None, digests=None
9992 ):
9993 maskbuf = mupdf.FzBuffer()
9994 page = self._pdf_page()
9995 # This will create an empty PdfDocument with a call to
9996 # pdf_new_document() then assign page.doc()'s return value to it (which
9997 # drop the original empty pdf_document).
9998 pdf = page.doc()
9999 w = width
10000 h = height
10001 img_xref = xref
10002 rc_digest = 0
10003
10004 do_process_pixmap = 1
10005 do_process_stream = 1
10006 do_have_imask = 1
10007 do_have_image = 1
10008 do_have_xref = 1
10009
10010 if xref > 0:
10011 ref = mupdf.pdf_new_indirect(pdf, xref, 0)
10012 w = mupdf.pdf_to_int( mupdf.pdf_dict_geta( ref, PDF_NAME('Width'), PDF_NAME('W')))
10013 h = mupdf.pdf_to_int( mupdf.pdf_dict_geta( ref, PDF_NAME('Height'), PDF_NAME('H')))
10014 if w + h == 0:
10015 raise ValueError( MSG_IS_NO_IMAGE)
10016 #goto have_xref()
10017 do_process_pixmap = 0
10018 do_process_stream = 0
10019 do_have_imask = 0
10020 do_have_image = 0
10021
10022 else:
10023 if stream:
10024 imgbuf = JM_BufferFromBytes(stream)
10025 do_process_pixmap = 0
10026 else:
10027 if filename:
10028 imgbuf = mupdf.fz_read_file(filename)
10029 #goto have_stream()
10030 do_process_pixmap = 0
10031
10032 if do_process_pixmap:
10033 #log( 'do_process_pixmap')
10034 # process pixmap ---------------------------------
10035 arg_pix = pixmap.this
10036 w = arg_pix.w()
10037 h = arg_pix.h()
10038 digest = mupdf.fz_md5_pixmap2(arg_pix)
10039 md5_py = digest
10040 temp = digests.get(md5_py, None)
10041 if temp is not None:
10042 img_xref = temp
10043 ref = mupdf.pdf_new_indirect(page.doc(), img_xref, 0)
10044 #goto have_xref()
10045 do_process_stream = 0

Callers 2

insert_imageMethod · 0.80
insert_imageFunction · 0.80

Calls 12

_pdf_pageMethod · 0.95
PDF_NAMEFunction · 0.85
JM_BufferFromBytesFunction · 0.85
JM_add_oc_objectFunction · 0.85
calc_image_matrixFunction · 0.85
_format_gFunction · 0.85
JM_insert_contentsFunction · 0.85
wMethod · 0.80
hMethod · 0.80
alphaMethod · 0.80
colorspaceMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected