Skip to content

Mismatch between images displayed and named in /Resources #2745

@frischzenger

Description

@frischzenger

Please provide all mandatory information!

Describe the bug (mandatory)

When extract image from current page, it will returns all page's images

To Reproduce (mandatory)

def extract_image():
doc = fitz.open("xxxxxxx.pdf") # open a document

for page_index in range(len(doc)): # iterate over pdf pages
    page = doc[page_index] # get the page
    image_list = page.get_images()
	
    # print the number of images found on the page
    if image_list:
        print(f"Found {len(image_list)} images on page {page_index}")
    else:
        print("No images found on page", page_index)
        
    for image_index, img in enumerate(image_list, start=1): # enumerate the image list
        xref = img[0] # get the XREF of the image
        pix = fitz.Pixmap(doc, xref) # create a Pixmap

        if pix.n - pix.alpha > 3: # CMYK: convert to RGB first
            pix = fitz.Pixmap(fitz.csRGB, pix)

        pix.save(".\\tmp\\page_%s-image_%s.png" % (page_index, image_index)) # save the image as png
        pix = None

Expected behavior (optional)

When extract image from current page, it will returns current page's images

Screenshots (optional)

Your configuration (mandatory)

  • Window11 home edition
  • Anaconda3 python3.10
  • PyMuPDF version('1.23.5', '1.23.4', '20231011000001')

Additional context (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    not a bugnot a bug / user error / unable to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions