图片批量转换工具
实现功能:
1.预算剩余时间
2.预测剩余进度
3.转换大小
4.自动调整比列
5.显示转换所有时间
6.显示调整所用时间
7.显示征途所有时间
下面给出程序源代码(r.vbs)
oh=640 '最大高度
op=10 '运行完等待时间,默认1000,即1秒
Function Mappath(v)
Mappath=fso.getAbsolutePathName(v)
End Function
Sub Convert
imgnum=fpo.files.count
wscript.echo "图片批量转换工具 1.0 By 苗启源"&vbCrlf&String(60,"=")
imgsta=timer()
imgi=1
for each file in fpo.files
if ucase(fso.getExtensionName(file))="JPG" Then
imgedit=timer()
wscript.echo "开始"&file.name&"转换..."
jpeg.open file
owidth=jpeg.originalwidth
oheight=jpeg.originalheight
if owidth>oheight then
whedit=timer()
om=(owidth-oheight)/2
jpeg.crop 0,0-om,owidth,oheight+om
wscript.echo "调整长宽比完毕,用时"&(timer()-whedit)*1000&"毫秒。"
end if
if jpeg.height>oh then
resizeedit=timer()
jpeg.width=oh*jpeg.width/jpeg.height
jpeg.height=oh
wscript.echo "压缩图片完毕,用时"&(timer()-resizeedit)*1000&"毫秒。"
end if
wscript.echo "原大小:"&oWidth&"x"&oHeight&",现大小:"&jpeg.width&"x"&jpeg.height
jpeg.save file
jpeg.close
wscript.echo file.name&"转换完毕,用时"&(timer()-imgedit)*1000&"毫秒。"
wscript.echo "当前进度"&CLng((imgi/imgnum)*10000)/100&"%,已开始"&(timer-imgsta)&"秒,预计还剩"&cint((imgnum-imgi)*(timer-imgsta)/imgi)&"秒。"&vbCrlf
wscript.sleep op
end if
imgi=imgi+1
next
wscript.echo String(60,"=")&vbCrlf&"转换完毕。"
wscript.sleep 10000
End Sub
set fso=CreateObject("Scripting.FileSystemObject")
set jpeg=CreateObject("Persits.JPEG")
set fpo=fso.getFolder(Mappath(""))
Convert