备忘之:)

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. ES6核心内容精讲--快速实践ES6(一)

    前言 本文大量参考了阮一峰老师的开源教程ECMAScript6入门,适合新手入门或者对ES6常用知识点进行全面回顾,目标是以较少的篇幅涵盖ES6及部分ES7在实践中的绝大多数使用场景.更全面.更深入的 ...

  2. 刨根究底字符编码之四——EASCII及ISO 8859字符编码方案

    EASCII及ISO 8859字符编码方案   1. 计算机出现之后,从美国发展到欧洲,由于欧洲很多国家中所用到的字符中,除了基本的美国也用的那128个ASCII字符之外,还有很多衍生的拉丁字母等字符 ...

  3. org.hibernate.LazyInitializationException...no session or session was closed

    org.hibernate.LazyInitializationException:failed to lazily initialize a collection of role:cn.its.oa ...

  4. OpenCV探索之路(十六):图像矫正技术深入探讨

    刚进入实验室导师就交给我一个任务,就是让我设计算法给图像进行矫正.哎呀,我不太会图像这块啊,不过还是接下来了,硬着头皮开干吧! 那什么是图像的矫正呢?举个例子就好明白了. 我的好朋友小明给我拍了这几张 ...

  5. socket.io搭配pm2(cluster)集群解决方案

    socket.io与cluster 在线上系统中,需要使用node的多进程模型,我们可以自己实现简易的基于cluster模式的socket分发模型,也可以使用比较稳定的pm2这样进程管理工具.在常规的 ...

  6. 数据库插入数据失败,log提示不能将值 NULL 插入列 'id'

    已经记不住具体的log信息了,意思就是ID如果没有设置为自增长的情况下就不能插入数据,而建表时ID字段是设置为"not null",所以就不能顺利插入数据. 解决方法有两种: ①建 ...

  7. 提高java编程质量 - (二)取余用偶判断,不要用奇判断

    取余判断原则:取余用偶判断,不要用奇判断 先看一个 程序: package com.test; import java.util.Scanner; public class t1 { public s ...

  8. python web -- flask

    Flask是一个简洁的 Python_web 框架. 零. virtualenv 虚拟环境配置. $ easy_install pip $ pip install virtualenv $ virtu ...

  9. Ionic在Android上部署app步骤

    详情链接:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/ionic%E5%9C%A8android%E4%B8%8A%E9%83% ...

  10. 有关Dom的一些操作

    学习前端的都会了解到一些Dom操作,让我们来看看Dom操作有哪些吧! DOM(即 Document Object Mode) 是 W3C(万维网联盟)的标准. DOM 定义了访问 HTML 和 XML ...