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 ...
随机推荐
- Azure IoT Hub和Event Hub相关的技术系列-索引篇
Azure IoT Hub和Event Hub相关的技术系列,最近已经整理了不少了,统一做一个索引链接,置顶. Azure IoT 技术研究系列1-入门篇 Azure IoT 技术研究系列2-设备注册 ...
- Nginx+Tomcat+MemCached 集群配置手册
系统实施文档 Nginx+Tomcat+MemCached 集群配置手册 目 录 第1章 概述 1.1 目标 互联网的快速发展带来了互联网系统的高负载和高可用性, 这要求我们在设计系统架 ...
- 开涛spring3(6.9) - AOP 之 6.9 代理机制
Spring AOP通过代理模式实现,目前支持两种代理:JDK动态代理.CGLIB代理来创建AOP代理,Spring建议优先使用JDK动态代理. JDK动态代理:使用java.lang.reflect ...
- Segmentation Faul
转自:http://www.cnblogs.com/panfeng412/archive/2011/11/06/segmentation-fault-in-linux.html
- ftp服务器可以连接但不能传输数据(proftpd)
问题:在客户端连接FTP服务器(proftpd)时可以正常连接,但是无法正常传输数据 ftp> ls530 Please login with USER and PASSPassive mode ...
- 将数据的初始化放到docker中的整个工作过程(问题记录)
将数据的初始化放到docker中的整个工作过程 由于是打算作为个人博客,所以对于install这个步骤,我从一开始就打算删掉的,前面一个多星期一直在修bug,到前天才开始做这个事情. 过程中也是碰到了 ...
- 低版本eclipse导入高版本eclipse创建项目报错问题
例如用高版本eclipse创建的项目,会默认使用的是jdk1.8版本, 低版本eclipse创建项目,会默认使用的是jdk1.7版本. 此时导入高版本eclipse项目时会报错(文件夹中会出现红色!) ...
- lucene全文搜索之四:创建索引搜索器、6种文档搜索器实现以及搜索结果分析(结合IKAnalyzer分词器的搜索器)基于lucene5.5.3
前言: 前面几章已经很详细的讲解了如何创建索引器对索引进行增删查(没有更新操作).如何管理索引目录以及如何使用分词器,上一章讲解了如何生成索引字段和创建索引文档,并把创建的索引文档保存到索引目录,到这 ...
- [转]以新浪为例浅谈XSS
随着网络时代的飞速发展,网络安全问题越来越受大家的关注,而SQL注入的攻击也随着各种防注入的出现开始慢慢的离我们而去,从而XSS跨站脚本攻击也慢慢的开始在最近几年崛起,也应对了’没有绝对的安全’这句话 ...
- Netty方法误解ChannelHandlerContext.writeAndFlush(Object msg)
乍一看这个方法,以为什么消息都能输出,因为参数是Object类型的,但实际上,netty内部只支持两种类型,如图