From PIL import imageimport osimport os.pathrootdir = R ' d:\ user directory \ My picture \from yun\ background map \ Background ' # indicates the folder being traversed for parent, dirname S, filenames in Os.walk (RootDir): to filename in filenames: print (' Parent is: ' + parent ') print (' filename is : ' + filename ' Currentpath = os.path.join (parent, filename) print (' The fulll name of the file is: ' + Currentpath ) im = Image.open (currentpath) out = Im.transpose (image.flip_left_right) newname=r "d:\ user directory \ My Pictures \from yun\ background \ Background graph inversion "+ ' \ \ ' +filename+" (1). jpg " out.save (newname) # im = Image.open (r ' C:\Users\Administrator\Desktop\ New Folder (2) \1.jpg ') # out = Im.transpose (image.flip_left_right) # Out.save (R ' C:\Users\Administrator\Desktop\ new folder (2) \ Test2.jpg ')
The last three lines are testing whether the horizontal rollover takes effect on a single picture and is found to be feasible.
The key is from PIL import image This module has been looking for me for a long time,-_-.
And the penultimate line of Im.transpose (Image.flip_left_right) is the core statement of the horizontal flip of the picture.
Ps:print statements can be deleted.
PPS: about why to do this, in fact, I have a lot of from the Internet (manual funny) Pictures carefully look at the level of the flip after, it looks very awkward, and then try to solve it.
Python's batch flips the picture horizontally