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

Method extract_image

src/__init__.py:4600–4628  ·  view source on GitHub ↗

Get image by xref. Returns a dictionary.

(self, xref)

Source from the content-addressed store, hash-verified

4598 return rc
4599
4600 def extract_image(self, xref):
4601 """Get image by xref. Returns a dictionary."""
4602 if self.is_closed or self.is_encrypted:
4603 raise ValueError("document closed or encrypted")
4604
4605 pdf = _as_pdf_document(self)
4606
4607 if not _INRANGE(xref, 1, mupdf.pdf_xref_len(pdf)-1):
4608 raise ValueError( MSG_BAD_XREF)
4609
4610 obj = mupdf.pdf_new_indirect(pdf, xref, 0)
4611 subtype = mupdf.pdf_dict_get(obj, PDF_NAME('Subtype'))
4612
4613 if not mupdf.pdf_name_eq(subtype, PDF_NAME('Image')):
4614 raise ValueError( "not an image")
4615
4616 o = mupdf.pdf_dict_geta(obj, PDF_NAME('SMask'), PDF_NAME('Mask'))
4617 if o.m_internal:
4618 smask = mupdf.pdf_to_num(o)
4619 else:
4620 smask = 0
4621
4622 # load the image
4623 img = mupdf.pdf_load_image(pdf, obj)
4624 rc = dict()
4625 _make_image_dict(img, rc)
4626 rc[dictkey_smask] = smask
4627 rc[dictkey_cs_name] = mupdf.fz_colorspace_name(img.colorspace())
4628 return rc
4629
4630 def ez_save(
4631 self,

Callers 7

recoverpixFunction · 0.80
recoverpixFunction · 0.80
test_3087Function · 0.80
test_pdfpixmapFunction · 0.80
test_2369Function · 0.80
test_extract_imageFunction · 0.80
test_2348Function · 0.80

Calls 5

_as_pdf_documentFunction · 0.85
_INRANGEFunction · 0.85
PDF_NAMEFunction · 0.85
_make_image_dictFunction · 0.85
colorspaceMethod · 0.80

Tested by 5

test_3087Function · 0.64
test_pdfpixmapFunction · 0.64
test_2369Function · 0.64
test_extract_imageFunction · 0.64
test_2348Function · 0.64