title: Page Orientation when converting images to pdf using FPDF (python)
body: <p>I am trying to convert a folder of images(jpg) into PDFs using FPDF. This code works great for the images in portrait format. For the images in landscape though it puts them on the portrait format. Is there a way to detect orientation and assign that to the pdf?</p>
  
  <p><a href="https://i.stack.imgur.com/PlPRa.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PlPRa.jpg" alt="enter image description here"></a></p>
  
  <p><strong>updated code for fix</strong></p>
  
  <pre><code>from fpdf import FPDF
  from PIL import Image
  import glob
  import os
  
  image_directory = r'C:\coolbro\test\yay\test'
  
  extensions = ('*.jpg','*.png','*.gif')
  
  imagelist=[]
  for ext in extensions:
      imagelist.extend(glob.glob(os.path.join(image_directory,ext)))
  
  for imagePath in imagelist:
  
  
      cover = Image.open(imagePath)
      width, height = cover.size
  
      if height &gt; width:
  
          pdf = FPDF(unit = "pt", format = "legal")
  
          pdf.add_page()
  
          pdf.image(imagePath, 0, 0, 600)
  
          destination = os.path.splitext(imagePath)[0]
          pdf.output(destination + ".pdf", "F")
  
      if width &gt; height:
  
          pdf = FPDF("L", unit = "pt", format = "legal")
  
          pdf.add_page()
  
          pdf.image(imagePath, 0, 0, 0, 600)
  
          destination = os.path.splitext(imagePath)[0]
          pdf.output(destination + ".pdf", "F")
  </code></pre>