title: Python PIL - AttributeError: 'NoneType' object has no attribute 'save'
body: <p>I use this code to delete the border of an image using PIL:</p>
  
  <pre><code>def RemoveBlackBorders(img):
      bg = Image.new(img.mode, img.size, img.getpixel((0,0)))
      diff = ImageChops.difference(img, bg)
      diff = ImageChops.add(diff, diff, 2.0, -100)
      bbox = diff.getbbox()
      if bbox:
          return img.crop(bbox)
  </code></pre>
  
  <p>from <a href="https://stackoverflow.com/questions/10615901/trim-whitespace-using-pil/10616717#10616717">here</a></p>
  
  <p>And I use this to process all images contained in a folder:</p>
  
  <pre><code>def CropImages():
      global FOLDER
      for i in range(1, len(os.listdir(FOLDER))+1):
          image = FOLDER + "\\" + str(i) + ".jpg"
          img = Image.open(image)
          img = RemoveBlackBorders(img)
          img.save(image, "JPEG")
  </code></pre>
  
  <p>Everything works fine and the program does his job. The problem is that if in the folder there is a full black image (which is detected as "border"), the program stuck giving me the error:</p>
  
  <pre><code> AttributeError: 'NoneType' object has no attribute 'save'
  </code></pre>
  
  <p>None of the images in the folder get cropped, even if the black image is the last one of the series. Is there a way to skip this image or delete it (which would be better)?</p>