Python's batch flips the picture horizontally

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.