Python bulk proportionally reduces picture script sharing

Source: Internet
Author: User
Tags glob
The picture is too big, hundreds of pictures with Photoshop to change too slowly, think of Python to write a simple batch processing. Simple function is to reduce the original image proportionally

Copy the Code code as follows:


Import Image
Import Glob, OS

Def timage ():
For files in Glob.glob (' d:\\\\1\\\\*. JPG '):
Filepath,filename = Os.path.split (Files)
filterame,exts = os.path.splitext (filename)
Opfile = R ' d:\\\\22\\\\ '
#判断opfile是否存在, does not exist then creates
if (Os.path.isdir (opfile) ==false):
Os.mkdir (Opfile)
im = (files)
W,h = Im.size
#im_ss = Im.resize ((400,400))
#im_ss = Im.convert (' P ')
IM_SS = Im.resize ((int (w*0.12), int (h*0.12))) (opfile+filterame+ '. jpg ')

If __name__== ' __main__ ':
Timage ()

print ' Haha finished '

  • Related Article

    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: 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.