This article mainly introduces the Python batch scaled down picture script sharing, this article directly gives the realization code, needs the friend may refer to under
The picture is too big, the hundreds of pictures in Photoshop to change too slow, think of using Python to write a simple batch process. Simple function is to reduce the original image proportionally
The code is as follows:
#-*-coding:cp936-*-
Import Image
Import Glob, OS
#图片批处理
Def timage ():
For the files in Glob.glob (' d:1*. JPG '):
Filepath,filename = Os.path.split (Files)
filterame,exts = os.path.splitext (filename)
#输出路径
Opfile = R ' d:22 '
#判断opfile是否存在, create if not present
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 '