diy toy: image auto-handler
备忘之:)
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的更多相关文章
- 你好,C++(11)如何用string数据类型表示一串文字?根据初始值自动推断数据类型的auto关键字(C++ 11)
3.5.2 字符串类型 使用char类型的变量我们可以表示单个字符,那么,我们又该如何表示拥有多个字符的字符串呢? 我们注意到,一个字符串是由多个字符串连起来形成的.很自然地,一种最简单直接的方法就 ...
- Android开发学习之路-图片颜色获取器开发(1)
系列第一篇,从简单的开始,一步一步完成这个小项目. 颜色获取就是通过分析图片中的每个像素的颜色,来分析整个图片的主调颜色,有了主调颜色,我们可以用于图片所在卡片的背景或者标题颜色,这样整体感更加强烈. ...
- Win32API界面库 - Project wheels 工程基础部分完成
离上次发博文过去了好久,先是要忙一个机器人的项目,然后就是部门的事情和考试周复习,然后就到了考试周,趁着复习的间隙,拾起了寒假时候抄的界面库,修掉了从前的bug. bug1 控件显示问题 当初抄这个库 ...
- cocos2d-x之加法计算器
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getIn ...
- CPP11实践
- 001 以lambda作为返回值该如何声明? 标准库提供了function模板可以直接声明,如std::function<void (int, int)>.如下函数foo返回了一个函数 ...
- electron api sendInputEvent 源码
electron-master\electron-master\shell\browser\api\atom_api_web_contents.cc // Copyright (c) 2014 Git ...
- c++ 反汇编 异常处理
c++异常处理 int main(){ try { throw 1; } catch ( int e ) { printf("catch int\r\n"); } catch ( ...
- iOS 8 Auto Layout界面自动布局系列5-自身内容尺寸约束、修改约束、布局动画
首先感谢众多网友的支持,最近我实在是事情太多,所以没有写太多.不过看到大家的反馈和评价,我还是要坚持挤出时间给大家分享我的经验.如果你对我写的东西有任何建议.意见或者疑问,请到我的CSDN博客留言: ...
- 智能提示含查询多列(html+JS+handler+ HttpRemoting)一、html示列 加 JS加 请求 Handler
<html> <head> </head> <body> <form id="recordform" name="r ...
随机推荐
- Linux中重定向
转:http://blog.csdn.net/songyang516/article/details/6758256 1重定向 1.1 重定向符号 > 输出 ...
- SmartCoder每日站立会议07
站立会议内容 基本框架已出,首页地图功能还没有接入完全. 1.站立会议照片: 2.任务展板 3.燃尽图
- 2017-5-22 ASP六大 内置对象
ASP内置对象:提供内建对象,这些对象使用户更容易收集通过浏览器请 求发送的信息.响应浏览器以及存储用户信息(如用户首选项). 1.Request --- 获取请求对象 获取通过地址栏传值过来的对象 ...
- Js之浅谈dom操作
JavaScript之浅谈dom操作 1.理解dom: DOM(Document Object Model ,文档对象模型)一种独立于语言,用于操作xml,html文档的应用编程接口. 怎么说,我从两 ...
- 对 Servlet 的改进--------Struts2 引入
通过上一篇博客:Servlet 的详解 http://www.cnblogs.com/ysocean/p/6912191.html,我们大致知道了 Servlet 的基本用法.但是稍微分析一下 Ser ...
- VR全景智慧城市——宣传再华丽,不如用户亲身参与
在当今社会上,VR和AI已经成为黑科技的代名词了.同样都是很热门的科技,但是它们的出场方式却差距不小.AI的出场方式是很有科技范,而VR的出场方式却是土豪气十足. 营销是什么,是通过制造爆点,用爆点实 ...
- QT环境的搭建
说到QT大家一定要先了解到底什么是QT,我们通常说的QT是包括:Qt-creactor的集成开发环境(IDE)和Qt的开发工具包(SDK),而Qt-creactor就相当于我们的visio studi ...
- sqlserver删除重复的数据
分享链接: http://blog.csdn.net/s630730701/article/details/52033018 http://blog.csdn.net/anya/article/det ...
- linux升级openssh7.4sp1
1.准备相关的包 openssh下载地址:http://mirror.internode.on.net/pub/OpenBSD/OpenSSH/portable/ openssl相关包下载:http: ...
- NOSQL基础概念
NoSql是一个很老的概念了,但对自己来说,仍然是一个短板,果断补上. 首先通过几个简单的例子来了解NOSQL在国内的情况(2013年左右的数据,有些过时),比如新浪微博,其就有200多台物理机运行着 ...