备忘之:)

config.xml

<?xml version="1.0" encoding="utf-8"?>
<config>
<zoom width="1296" height="100">
</zoom>
<rotation angle="270">
</rotation>
<save>
<path>D:\0122</path>
</save>
<author prefix="xxoo">
</author>
<monitor total="10">
</monitor>
</config>

image-auto-handler.vbs

 'Whatfor:  rename pictures with Exif property [artist]
'Author: lichmama nextgodhand@163.com
'Runtime: win-NT series(x86/x64), which installed WIA component.
'LICENSE:
' Copyright ;copy; 2014-2015 lichmama nextgodhand@163.com
' All rights reserved.
' FOR NON-COMMERCIAL USE: you can use, copy, modify and distribute this code,
' but please keep the information of LICENSE & Author. '*ChangeLog:
' 1.add zoom and rotation
' 2.backup the folder [*.NEW] to config path
' reedited: 2015/04/16
' 3.change the naming style, which supports the [alpha] property
' 3.*not keeping the folder [*.NEW]
' reedited: 2015/10/27
' 4.add monitor function, which supports the [total] property
' reedited: 2015/10/31, happy halloween:)
' 5.change the config file to config.xml [original, config.ini]
' 5.*add verifying for configurations
' reedited: 2015/11/1 Set fso = CreateObject("scripting.filesystemobject")
Set imgfile = CreateObject("wia.imagefile")
Set sdp = CreateObject("scripting.dictionary")
Set regex = CreateObject("vbscript.regexp")
Set monitor = CreateObject("scripting.dictionary")
set config = new Config_Class '================script starts!================
Call sdp.Add("PNG", "PNG FILE")
Call sdp.Add("GIF", "GIF FILE")
Call sdp.Add("BMP", "BMP FILE")
Call sdp.Add("JPG", "JPG FILE") If WScript.Arguments.Count = Then
Call Quit_Job(True)
Else
path = WScript.Arguments()
If Not fso.FolderExists(path) Then
Call Quit_Job(True)
End If
End If If Not ReadConfig() Then
Call Wscript.Echo("[配置文件错误]:运行前请保证配置文件config.ini存在,并且正确!")
Call Quit_Job(False)
End If If Not fso.FolderExists(path & ".NEW") Then
Call fso.CreateFolder(path & ".NEW")
End If For Each picture In fso.GetFolder(path).Files
extension = UCase(fso.GetExtensionName(picture))
If sdp.Exists(extension) Then
Call imgfile.LoadFile(picture)
For index = To imgfile.Properties.Count
name = imgfile.Properties(index).Name
If name = "Artist" Then
regex.Pattern ="\d*"
value = imgfile.Properties(index).Value
value = regex.Execute(value)()
index = CInt(value)
regex.Pattern = "^(0*)"
value = regex.Replace(value, config.author_prefix)
Call Zoom_Rotate()
Call imgfile.SaveFile(path & ".NEW\" & value & "." & extension)
monitor.Item(index) = path & ".NEW\" & value & "." & extension
Exit For
End If
Next
End If
Next
Call Monitor_Total() 'move the folder [*.NEW] to config path
regex.Pattern = "([^\\]+)$"
dest = fso.GetAbsolutePathName(path)
dest = regex.Execute(dest)().SubMatches()
For i= To config.save_path.Count-
Call fso.CopyFolder(path & ".NEW", config.save_path.Item(i) & "\" & dest)
Next
Call fso.DeleteFolder(path & ".NEW") MsgBox "批处理执行完毕!",vbInformation,"Image Auto-Handler v0.1"
Call Quit_Job(False)
'================script ends here==============
Function ReadConfig()
On Error Resume Next
xmlsource = Replace(WScript.ScriptFullName, WScript.ScriptName, "config.xml")
If fso.FileExists(xmlsource) Then
Call config.init_config(xmlsource)
For i = To config.monitor_total
Call monitor.Add(i, "")
Next
For i = To config.save_path.Count-
If Not fso.FolderExists(config.save_path.Item(i)) Then
WScript.Echo "[配置文件错误]:保存路径不存在!"
Call Quit_Job(False)
End If
Next
ReadConfig = True
Else
ReadConfig = False
End If
If Err.Number <> Then
ReadConfig = False
End If
End Function Sub Monitor_Total()
regex.Pattern = "(" & config.author_prefix & ")\d+"
If monitor.Item() = "" Then
For i = To monitor.Count
If monitor.Item(i) <> "" Then
clone = regex.Replace(monitor.Item(i), "$1" & )
monitor.Item() = clone
Call fso.CopyFile(monitor.Item(i), monitor.Item())
Exit For
End If
Next
End If For i = To monitor.Count
If monitor.Item(i) = "" Then
clone = regex.Replace(monitor.Item(i-), "$1" & i)
monitor.Item(i) = clone
Call fso.CopyFile(monitor.Item(i-), monitor.Item(i))
End If
Next
End Sub Sub Zoom_Rotate()
Set imgproc = CreateObject("wia.imageprocess")
'zoom
Call imgproc.Filters.Add(imgproc.FilterInfos("Scale").FilterID)
imgproc.Filters().Properties("MaximumWidth") = config.zoom_width
imgproc.Filters().Properties("MaximumHeight") = config.zoom_width
'rotate
Call imgproc.Filters.Add(imgproc.FilterInfos("RotateFlip").FilterID)
imgproc.Filters().Properties("RotationAngle") =
'apply
Set imgfile = imgproc.Apply(imgfile)
End Sub Sub Quit_Job(force)
If force = True Then
MsgBox "[使用方法]: 将文件夹拖放到脚本上,开始重命名图片。", vbInformation, "Image Auto-Handler v0.1"
End If
Set fso = Nothing
Set imgfile = Nothing
Set sdp = Nothing
Set regex = Nothing
Set monitor = Nothing
Call WScript.Quit()
End Sub Class Config_Class
Private my_zoom_width
Private my_zoom_height
Private my_rotation_angle
Private my_save_path
Private my_author_prefix
Private my_monitor_total Public Sub init_config(xmlsource)
Set xml = CreateObject("msxml2.domdocument")
Call xml.load(xmlsource) Set zoom = xml.getElementsByTagName("zoom").item()
my_zoom_width = zoom.attributes.getNamedItem("width").text
my_zoom_height = CInt(zoom.attributes.getNamedItem("height").text) Set rotation = xml.getElementsByTagName("rotation").item()
my_rotation_angle = rotation.attributes.getNamedItem("angle").text Set save = xml.getElementsByTagName("save").item()
Set my_save_path = CreateObject("scripting.dictionary")
For i = To save.childNodes.length -
Call my_save_path.Add(i, save.childNodes.item(i).text)
Next Set author = xml.getElementsByTagName("author").item()
my_author_prefix = author.attributes.getNamedItem("prefix").text Set xml_monitor = xml.getElementsByTagName("monitor").item()
my_monitor_total = xml_monitor.attributes.getNamedItem("total").text
End Sub Public Property Get zoom_width
zoom_width = my_zoom_width
End Property Public Property Get zoom_height
zoom_height = my_zoom_height
End Property Public Property Get rotation_angle
rotation_angle = my_rotation_angle
End Property Public Property Get save_path
Set save_path = my_save_path
End Property Public Property Get author_prefix
author_prefix = my_author_prefix
End Property Public Property Get monitor_total
monitor_total = my_monitor_total
End Property
End Class

diy toy: image auto-handler的更多相关文章

  1. 你好,C++(11)如何用string数据类型表示一串文字?根据初始值自动推断数据类型的auto关键字(C++ 11)

    3.5.2  字符串类型 使用char类型的变量我们可以表示单个字符,那么,我们又该如何表示拥有多个字符的字符串呢? 我们注意到,一个字符串是由多个字符串连起来形成的.很自然地,一种最简单直接的方法就 ...

  2. Android开发学习之路-图片颜色获取器开发(1)

    系列第一篇,从简单的开始,一步一步完成这个小项目. 颜色获取就是通过分析图片中的每个像素的颜色,来分析整个图片的主调颜色,有了主调颜色,我们可以用于图片所在卡片的背景或者标题颜色,这样整体感更加强烈. ...

  3. Win32API界面库 - Project wheels 工程基础部分完成

    离上次发博文过去了好久,先是要忙一个机器人的项目,然后就是部门的事情和考试周复习,然后就到了考试周,趁着复习的间隙,拾起了寒假时候抄的界面库,修掉了从前的bug. bug1 控件显示问题 当初抄这个库 ...

  4. cocos2d-x之加法计算器

    bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getIn ...

  5. CPP11实践

    - 001 以lambda作为返回值该如何声明? 标准库提供了function模板可以直接声明,如std::function<void (int, int)>.如下函数foo返回了一个函数 ...

  6. electron api sendInputEvent 源码

    electron-master\electron-master\shell\browser\api\atom_api_web_contents.cc // Copyright (c) 2014 Git ...

  7. c++ 反汇编 异常处理

    c++异常处理 int main(){ try { throw 1; } catch ( int e ) { printf("catch int\r\n"); } catch ( ...

  8. iOS 8 Auto Layout界面自动布局系列5-自身内容尺寸约束、修改约束、布局动画

    首先感谢众多网友的支持,最近我实在是事情太多,所以没有写太多.不过看到大家的反馈和评价,我还是要坚持挤出时间给大家分享我的经验.如果你对我写的东西有任何建议.意见或者疑问,请到我的CSDN博客留言: ...

  9. 智能提示含查询多列(html+JS+handler+ HttpRemoting)一、html示列 加 JS加 请求 Handler

    <html> <head> </head> <body> <form id="recordform" name="r ...

随机推荐

  1. Ubuntu安装中文输入法

    如果你没有因为各种尝试搞乱了Ubuntu系统的话: 1. 在All Settings 里找到 Language Support, Install/Remove Languages里安装Chinese ...

  2. javaWeb学习总结(10)- Filter(过滤器)学习

    一.Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有 web资源:例如Jsp, Servlet, 静 ...

  3. openfire muc 移除成员

    muc添加成员到数据库可参考 将Openfire中的MUC改造成类似QQ群一样的永久群 插件 插件是一位大神参考第一篇文章改进后编写的插件,进测试可以直接使用. ------------------- ...

  4. JS组件系列——自己动手扩展BootstrapTable的treegrid功能

    前言:上篇  JS组件系列——自己动手封装bootstrap-treegrid组件 博主自己动手封装了下treegrid的功能,但毕竟那个组件只是一个单独针对树形表格做的,适用性还比较有限.关注博主的 ...

  5. python爬虫从入门到放弃(七)之 PyQuery库的使用

    PyQuery库也是一个非常强大又灵活的网页解析库,如果你有前端开发经验的,都应该接触过jQuery,那么PyQuery就是你非常绝佳的选择,PyQuery 是 Python 仿照 jQuery 的严 ...

  6. 安卓ios和angularjs相互调用解决首次调用ios传递标题失败的问题

    1.angular 调用客户端方法放在 try catch中 try { js_invoke.showShareDialog(angular.toJson(obj));  // 在这里放客户端的方法即 ...

  7. 我做的第一个程序(菜鸟的java课堂笔记)

    内存: 堆区,栈区,常量区,计数区,代码区: 数据类型: 基本数据类型:整形,浮点型,布尔型 boolean 只能返回真假值,字符型: 引用数据类型:类,数组: 基本数据类型-->直接存放到栈区 ...

  8. python List和String 转换注意

    不能用str(list),t=['\x87\xe9\xa5\xb0\xef\xbc']In [28]: str(t)Out[28]: "['\\x87\\xe9\\xa5\\xb0\\xef ...

  9. Linux获取UUID

    Linux内核提供有UUID生成接口: cat /proc/sys/kernel/random/uuid Linux上一切皆文件,不管什么程序,读取文件就能获取一个UUID.

  10. cpp(第十四章)

    1.类的静态成员变量.静态常整型(static const int)变量可以直接在类声明中初始化,静态常变量(static const )需要在类定义文件中初始化, 常变量(const )则在构造函数 ...