title: Image Extraction using python
body: <p>I'm using using fitz to extract images from a PDF file but the output images aren't in the same order as in the pdf. Is there any method to extract these images in order.
  note: every page contains 2 images, and I want to extract the left one first then the right one.</p>
  <pre><code>for page_index in range(len(pdf_file)):                                                                                 
  if ( page_index &lt; 4 or page_index == len(pdf_file) - 1 ): continue                                                 
  # get the page itself
  page = pdf_file[page_index]
  image_list = page.getImageList()                                                                                
  
  v = 0
  for image_index, img in enumerate(page.getImageList(), start=1):
      if v == 0:                                                                                            
          v += 1
          continue
      # get the XREF of the image
      xref = img[0]
      # extract the image bytes
      base_image = pdf_file.extractImage(xref)
      image_bytes = base_image[&quot;image&quot;]
      # get the image extension
      image_ext = base_image[&quot;ext&quot;]
      # load it to PIL
      image = Image.open(io.BytesIO(image_bytes))
      # save it to local disk
  </code></pre>