Python batch scale down image script sharing in proportion,
The image is too large. If you use photoshop to change more than images, you can use python to write a simple batch. The simple function is to scale down the source image proportionally.
Copy codeThe Code is as follows:
#-*-Coding: cp936 -*-
Import Image
Import glob, OS
# Image Batch Processing
Def timage ():
For files in glob. glob ('d :\\\ 1 \\\\ *. JPG '):
Filepath, filename = OS. path. split (files)
Filterame, exts = OS. path. splitext (filename)
# Output path
Opfile = r 'd: \\\\ 22 \\\\'
# Determine whether the opfile exists. If the opfile does not exist, it is created.
If (OS. path. isdir (opfile) = False ):
OS. mkdir (opfile)
Im = Image. open (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 )))
Im_ss.save(opfile?filterame='.jpg ')
If _ name __= = '_ main __':
Timage ()
Print 'haha finished'