Skynet

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

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks


          工具為  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.aygfsteel.com/Good-Game
          posted on 2009-12-07 15:12 劉凱毅 閱讀(677) 評論(0)  編輯  收藏 所屬分類: pythonimage
          主站蜘蛛池模板: 绵竹市| 陆良县| 沙洋县| 米林县| 东莞市| 江城| 嘉兴市| 福泉市| 东明县| 水城县| 玛曲县| 皮山县| 吴桥县| 灌云县| 静乐县| 邓州市| 岳阳县| 江永县| 株洲县| 德兴市| 邯郸县| 靖州| 华池县| 绵竹市| 金溪县| 乌拉特前旗| 宁乡县| 兴安盟| 比如县| 定南县| 白河县| 龙口市| 加查县| 平乡县| 通山县| 屏山县| 屯门区| 玛纳斯县| 锡林郭勒盟| 武陟县| 齐河县|