工具为  dist/myImg.exe
工具使用:
在 dist 中
myImg.exe Ratio  c:/需要等比压缩图片/*.jpg  d:/等比后路径   等比款width  等比高height 
myImg.exe Watermark c:/水印图片/x.png  c:/需要加水印图片/*.jpg  d:/添加水印后图片   加水印width处  加水印height处
等比压缩实例:
myImg.exe Ratio  
    "C:"Documents and Settings"lky"My Documents"My Dropbox"tools"img"src"python"dist"test"img"*.jpg" 
    "C:"Documents and Settings"lky"My Documents"MyDropbox"tools"img"src"python"dist"test"toimg2" 
    600 400
结果在  ../dist"test"toimg  目录下 生成 等比图片 testratio_600_400.jpg
水印添加实例:
myImg.exe Watermark 
    "C:"Documents and Settings"lky"My Documents"My Dropbox"tools"img"src"python"dist"test"img"logo.png"   
    "C:"Documents and Settings"lky"My Documents"My Dropbox"tools"img"src"python"dist"test"toimg2"*.jpg" 
    "C:"Documents and Settings"lky"My Documents"My Dropbox"tools"img"src"python"dist"test"toimg3" 
    100 220
结果在  ../dist"test"toimg3  目录下 生成 等比图片 test_ratio_600_400_watermark_100_220.jpg
安装 python PIL 包
和安装 python py2exe 
工具脚本 py 
工具编译过程:
python setup.py py2exe 
import sys
def imgRatio(imgpath,tpath='.',width=600,height=400):
    import Image,os
    im = Image.open( imgpath )
    im.thumbnail( (width,height) )
    imgpath = os.path.split(imgpath)[1]
    if not os.path.exists(tpath) : os.makedirs(tpath)
    im.save( tpath+'/'+imgpath.split('.')[0]+'_ratio_'+str(width)+'_'+str(height)+'.jpg' )
def imgWatermark(imgwate,imgpath,sw=100,sh=50,tpath='.'):
    import Image,os
    baseim = Image.open( imgpath )
    floatim = Image.open( imgwate )
    baseim.paste( floatim, (sw,sh ) )
    imgpath = os.path.split(imgpath)[1]
    if not os.path.exists(tpath) : os.makedirs(tpath)
    baseim.save( tpath+'/'+imgpath.split('.')[0]+'_watermark_'+str(sw)+'_'+str(sh)+'.jpg' )
    
args = sys.argv
import glob,os
# Ratio  /path/*.jpg  /tpath   width  height  
if args[1] == 'Ratio' :
    for img in glob.glob(args[2]) :
        imgRatio(os.path.abspath(img),args[3],int(args[4]),int(args[5]))
# Watermark /path/x.png  /path/*.jpg  /tpath   width  height 
if args[1] == 'Watermark' :
    for img in glob.glob(args[3]) :
        imgWatermark(args[2],img,int(args[5]),int(args[6]),args[4])
py2exe
#!/usr/bin/python
# -*- coding: utf-8 -*-
#  py2exe file
# 1.install py2exe application
# 2.python setup.py py2exe
from distutils.core import setup
import py2exe
setup(console=['myImg.py'])
整理 www.blogjava.net/Good-Game