给自己的 图片处理工具 (py2exe)

简介:
工具为  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 ' ])
本文转自博客园刘凯毅的博客,原文链接:给自己的 图片处理工具 (py2exe),如需转载请自行联系原博主。
目录
相关文章
|
1月前
|
存储 缓存 Python
如何使用Python抓取PDF文件并自动下载到本地
如何使用Python抓取PDF文件并自动下载到本地
34 0
|
2月前
|
机器学习/深度学习 算法 计算机视觉
Yolov5 + 界面PyQt5 +.exe文件部署运行
Yolov5 + 界面PyQt5 +.exe文件部署运行
85 2
|
3月前
|
安全 编译器 开发者
Python打包成.exe文件直接运行
Python打包成.exe文件直接运行
112 1
|
2月前
|
Python
使用PyInstaller将Python应用程序打包成EXE文件
使用PyInstaller将Python应用程序打包成EXE文件
164 0
|
8月前
|
Python Windows
python 程序打包成桌面exe程序(上)
python 程序打包成桌面exe程序
164 0
|
8月前
|
存储 Python
python 程序打包成桌面exe程序(下)
python 程序打包成桌面exe程序
|
11月前
|
Python
Python 用os和win32api库模仿DOS命令dir (完整实例)
Python 用os和win32api库模仿DOS命令dir (完整实例)
111 0
|
11月前
|
数据安全/隐私保护 Python
Python抖音视频去水印,并打包成exe可执行文件
Python抖音视频去水印,并打包成exe可执行文件
331 0
|
Unix Linux iOS开发
Python打包为exe详细教程
Python打包为exe详细教程
Python打包为exe详细教程
|
Python
将python程序打包成exe文件和播放mp3
将python程序打包成exe文件和播放mp3
173 0