下载对应的安装包,这两有两种,第一种例如chardet是tar.gz之类的后缀,
解压之后用cmd进入该,python setup.py install 即可
另一种是exe,比如PIL-1.1.7.win32-py2.7.exe,直接运行即可。
Image模块的功能很强大,
介绍1 http://onlypython.group.iteye.com/group/wiki/1372-python-graphics-image-processing-library-introduced-the-image-module
另一个是批量处理图片的大小及各式
import os
import Image
srcImgFolder = srcImgFolder = r"C:\Users\wyr\Desktop\pytest\newfile"
def resizeFold(dir_proc):
for file in os.listdir(dir_proc):
fullFile = os.path.join(dir_proc, file) # join 变文件夹等为绝对整的路径
if os.path.isdir(fullFile): #isdir 是否该路径地下还有文件/文件夹
resizeFold(fullFile) # 递归
continue
#带有下划线的目标图片不需要处理
if fullFile.find("_") != -1:
continue
#正常图片
srcImgFullFileName = fullFile
# BaseUtil.outputInfoMessage("INFO:process file %s" %(os.path.join(dir_proc, file)))
#处理文件
if os.path.isfile(srcImgFullFileName): # 是文件
folderPath = srcImgFullFileName[:srcImgFullFileName.rfind(os.sep)] #获取文件的所在父路径,不包括自己
fileName = srcImgFullFileName[srcImgFullFileName.rfind("\\")+1:] #文件夹名
img = Image.open(srcImgFullFileName)
# img.show()
width,height = img.size
targetWidthArray = (100,120,240,400,640)
for targetWidth in targetWidthArray:
targetImg = img.resize(
(targetWidth, targetWidth * height / width),
Image.ANTIALIAS
)
newFileName = fileName.split(".")[0] + "_" + str(targetWidth) + "." + fileName.split(".")[1]
targetImg.save(folderPath + os.sep + newFileName, 'jpeg')
if __name__ == "__main__":
resizeFold(srcImgFolder)
元博客地址忘记了=..=