Skynet

          ---------- ---------- 我的新 blog : liukaiyi.cublog.cn ---------- ----------

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks


          工具為  dist/myImg.exe


          工具使用:
          在 dist 中
          myImg.exe Ratio  c:/需要等比壓縮圖片/*.jpg  d:/等比后路徑   等比款width  等比高h(yuǎn)eight
          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
          結(jié)果在  ../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
          結(jié)果在  ../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.aygfsteel.com/Good-Game
          posted on 2009-12-07 15:12 劉凱毅 閱讀(673) 評論(0)  編輯  收藏 所屬分類: pythonimage
          主站蜘蛛池模板: 秦皇岛市| 清涧县| 鲜城| 江安县| 广丰县| 长春市| 湾仔区| 辽阳市| 轮台县| 温州市| 即墨市| 新龙县| 彰化县| 阿荣旗| 石台县| 化德县| 肃南| 柞水县| 陕西省| 绵阳市| 南安市| 菏泽市| 吴江市| 东城区| 万盛区| 苏尼特左旗| 武冈市| 峨山| 汝南县| 阳高县| 安吉县| 观塘区| 湘阴县| 昭苏县| 东辽县| 丰都县| 韩城市| 思茅市| 疏勒县| 大厂| 清原|