备忘之:)

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. javaWeb学习总结(3)- Servlet总结(servlet的主要接口、类)

    Servlet总结01——servlet的主要接口.类 (一)servlet类 Servlet主要类.接口的结构如下图所示: 要编写一个Servlet需要实现javax.servlet.Servlet ...

  2. python中的数字

    在编程中,通常使用数字来记录游戏得分,表示可视化数据.存储web应用信息等. #运算# 1,基本运算 >>> 2+35>>> 1-2-1>>> 3 ...

  3. Hash Table Performance in R: Part I(转)

    What Is It? A hash table, or associative array, is a well known key-value data structure. In R there ...

  4. Git基础-打标签

    打标签 同大多数 VCS 一样,Git 也可以对某一时间点上的版本打上标签.人们在发布某个软件版本(比如 v1.0 等等)的时候,经常这么做.本节我们一起来学习如何列出所有可用的标签,如何新建标签,以 ...

  5. 错误处理1: D:\a1-C++\C++作业\第五次1.cpp undefined reference to `vtable for Shape'

    在编译程序的时候遇到此误,在google上查,很多地方都说是因为虚基类里面的虚拟析构函数没有提供实现导致的.但是我的已经提供了实现,也不行.最后发现是其他没有提供实现的虚函数造成的.所以,在一个虚基类 ...

  6. 用pickle模块实现“增删改查”的简易功能

    pickle的作用: 1:pickle.dump(dict,file)把字典转为二进制存入文件. 2:pickle.load(file)把文件二进制内容转为字典 import pickle # 增 d ...

  7. 【2017-06-06】Ajax完整结构、三级联动的制作

    一.Ajax完整结构 $.ajax({ url:"Main.ashx", data:{}, dataType:"json", type:"post&q ...

  8. SQL构架(转)

    在一次的实际工作中碰到以下情况,在 SQL SERVER 2008中,新建了一个新用户去访问几张由其他用户创建的表,但是无法进行查询,提示“对象名'CustomEntry' 无效.”.当带上了架构名称 ...

  9. css简单了解

    今天主要是说一下css样式表!HTML结合他使用可以是HTML页面变得很绚丽多彩! 先简单介绍一下为什么要使用CSS(Cascading Style Sheets)层叠样式表! 1.因为CSS样式表可 ...

  10. java 多线程基础

    线程是进程内的执行单元,进程当中都有若干个线程. 通常主线程或进程是阻塞式的按顺序执行的,如果希望异步执行些子任务,而不要阻塞当前线程的执行,即需要创建子线程,子线程创建后主线程可以等待它们的结果,得 ...