title: Cannot save EXIF data to a file
body: <p>I'm trying to make an app which restores the original date of the picture (the time in which it was taken) by it's name as the name of the picture contains its date on Android phones but I can't save the EXIF data.<br>
  No errors etc. it just does not save. I'm using PIL and piexif.  </p>
  
  <p>I tried literally everything here on Stackoverflow and other forums but none of the pieces of code worked.<br>
  My code looks like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>    def set_exif_tag(self, path, yr, m, d, hr):
          i = iter(hr)
          hr = ':'.join(a+b for a, b in zip(i, i))  # Put ":" every 2 chars
  
          exif_ifd = {
              piexif.ExifIFD.DateTimeOriginal: f"{yr}:{m}:{d} {hr}".encode(),
              piexif.ExifIFD.DateTimeDigitized: f"{yr}:{m}:{d} {hr}".encode()
          }
  
          exif_dict = {"Exif": exif_ifd}
          exif_bytes = piexif.dump(exif_dict)
          with open(path, 'r+b'):
              with Image.open(path) as img:
                  img.save(path, exif=exif_bytes)
          print("EXIF DICT: " + str(exif_dict))
          print("EXIF BYTES: " + str(bytes(exif_bytes)))
  </code></pre>