title: Python image save error - raise ValueError("unknown file extension: {}".format(ext)) from e ValueError: unknown file extension:
body: <p>Am just having four weeks of experience in Python. Creating a tool using Tkinter to paste a new company logo on top of the existing images.</p>
  <p>The Below method is to, get all images in the given directory and paste the new logo on the initial level. Existing image, edited image, x-position, y-position, a preview of the image and few data's are store in global instance <em>self.images_all_arr</em>.</p>
  <pre><code>def get_img_copy(self):
      self.images_all_arr = []
      existing_img_fldr = self.input_frame.input_frame_data['existing_img_folder']
      for file in os.listdir(existing_img_fldr):
          img_old = Image.open(os.path.join(existing_img_fldr, file))
          img_new_copy = img_old.copy()
          self.pasteImage(img_new_copy, initpaste=True) #process to paste new logo.
          view_new_img = ImageTk.PhotoImage(img_new_copy)
          fname, fext = file.split('.')
          formObj = {
              &quot;fname&quot;: fname,
              &quot;fext&quot;: fext,
              &quot;img_old&quot;: img_old,
              &quot;img_new&quot;: img_new_copy,
              &quot;img_new_view&quot;: view_new_img,
              &quot;add_logo&quot;: 1,
              &quot;is_default&quot;: 1,
              &quot;is_opacityImg&quot;: 0,
              &quot;pos_x&quot;: self.defult_x.get(),
              &quot;pos_y&quot;: self.defult_y.get()
          }
          self.images_all_arr.append(formObj)
  </code></pre>
  <p>After previewing each image in Tkinter screen, doing some adjustment in position x and y(updating pos_x and pos_y in the list <em>self.images_all_arr</em>) depends upon the necessity.</p>
  <p>Well, once all done. Need to save the edited images. Below method to save images, iterating the list <em>self.images_all_arr</em> and call save method as <em>img['img_new'].save(dir_output)</em> since <em>img['img_new']</em> has updated image.</p>
  <pre><code> def generate_imgae(self):
      if len(self.images_all_arr):
          dir_output = 'xxxxx'
          for img in self.images_all_arr:
              print(img['img_new'])
              img['img_new'].save(dir_output)
  
          print('completed..')
  </code></pre>
  <p>But it returns below error,</p>
  <blockquote>
  <p>Exception in Tkinter callback
  Traceback (most recent call last):
  File &quot;C:\Program Files (x86)\Python38-32\lib\site-packages\PIL\Image.py&quot;, line 2138, in save
  format = EXTENSION[ext]
  KeyError: ''
  The above exception was the direct cause of the following exception:
  Traceback (most recent call last):
  File &quot;C:\Program Files (x86)\Python38-32\lib\tkinter_<em>init</em>_.py&quot;, line 1883, in <strong>call</strong>
  return self.func(*args)
  File &quot;C:\Users\662828\WORKSPACE\AAA_python_projects\AMI_automation_poc2\position_and_images.py&quot;, line 241, in generate_imgae
  img['img_new'].save(dir_output)
  File &quot;C:\Program Files (x86)\Python38-32\lib\site-packages\PIL\Image.py&quot;, line 2140, in save
  raise ValueError(&quot;unknown file extension: {}&quot;.format(ext)) from e
  ValueError: unknown file extension:</p>
  </blockquote>