Demand is such, because now the camera pixel is very high, the photo is very big, upload to the online album too slow, so to first turn the size, before are directly in the online search image processing software, and then think about it, since the program, this demand can be done by themselves.
Python picture processing cool crooked, a few lines of code to fix, here is the Pillow library.
The code below.
#coding =utf-8from PIL Import image# requires Pillow Library import glob, Osin_dir = ' tmp_photo ' #源图片目录out_dir = in_dir+ ' _out ' # Converted Picture Catalog percent = 0.4# Scaling if not os.path.exists (Out_dir): Os.mkdir (Out_dir) #图片批处理def main (): For files in Glob.glob ( in_dir+ '/* '): filepath,filename = os.path.split (files) im = Image.open (files) w,h = Im.size im = Im.resize ((int (w*percent), int (h*percent))) Im.save (Os.path.join (out_dir,filename)) if __name__== ' __main__ ': Main ()
Batch convert pictures in Python