How to use python to imitate the opening and saving of an image file in an image editor?
问题 I encountered a certain problem with corrupt .png image files* that I was able to overcome by simply opening them in an image editor (Apple's Preview) and saving them back, without making any explicit changes. I have thousands of similarly corrupt image files that need to be subjected to the same procedure. Is there a way to automate it in python? The following naive code doesn't work: >>> with open('an_image.png', 'rb') as f: ... data = f.read() ... with open('an_image.png', 'wb') as f: ...