您现在的位置是:网站首页> 编程资料编程资料
VBS相册生成脚本[_vbs_
2023-05-25
335人已围观
简介 VBS相册生成脚本[_vbs_
此脚本的功能为将一个目录中的jpg,gif,png格式的图片生成Html相册,页面上的图像只是改变显示大小,并没有生成缩略图。
用到的技术:Scripting.FileSystemObject,Adodb.Stream。其中得到图片长宽用了秋水无恨的Adodb.Stream取得图像的高宽
'///////////////////////////////////////////////
'VBS相册生成脚本,使用方法:将此文件放在sendto目录中(在运行中输入直接sendto,就可以打开),然后在有图片的文件夹上点右键,选择发送到,等一下,就OK了。
'海娃 http://www.51windows.Net
'更新日期:2004-12-30
'///////////////////////////////////////////////
Set ArgObj = WScript.Arguments
Set fsoBrowse = CreateObject("Scripting.FileSystemObject")
dim cpath,imgw,imgh,pagesize,wn,hn,pagetitle,filenamestart,firstpage
cpath=ArgObj(0)'传递路径
imgw = 240
imgh = 180
wn = 3
hn = 3
pagetitle = "图片展示 - 51windows.Net"
filenamestart = "Page_"
firstpage = "index.htm"
pagetitle2 = inputbox("请输入页面标题","请输入页面标题",pagetitle)
if isempty(pagetitle2) = false and len(pagetitle2) > 1 then
pagetitle = pagetitle2
end if
filenamestart2 = inputbox("请输入文件名前缀","请输入文件名前缀",filenamestart)
if isempty(filenamestart2) = false and len(filenamestart2) > 1 then
filenamestart = filenamestart2
end if
firstpage2 = inputbox("请输入第一页的文件名,点取消按序号生成","请输入第一页的文件名",firstpage)
if isempty(firstpage2) = false and len(filenamestart2) > 1 then
firstpage = firstpage2
else
firstpage = ""
end if
if len(firstpage) > 0 and (right(lcase(firstpage),4)<>".htm" and right(lcase(firstpage),5)<>".html") then
firstpage = firstpage & ".htm"
end if
imgw2 = inputbox("请输入小图的宽度","请输入小图的宽度",imgw)
if isnumeric(imgw2) and isempty(imgw2) = false then
imgw = imgw2
end if
imgh2 = inputbox("请输入小图的高度","请输入小图的高度",imgh)
if isnumeric(imgh2) and isempty(imgh2) = false then
imgh = imgh2
end if
wn2 = inputbox("请输入每行的图像数","请输入每行的图像数",wn)
if isnumeric(wn2) and isempty(wn2) = false then
wn = wn2
end if
hn2 = inputbox("请输入行数","请输入行数",hn)
if isnumeric(hn2) and isempty(hn2) = false then
hn = hn2
end if
dim info
info = ""
pagesize = wn*hn
dim message
message = ""
message = message & "文件路径:" & chr(9) & cpath & vbnewline
message = message & "页面标题:" & chr(9) & pagetitle & vbnewline
message = message & "文件名前缀:" & chr(9) & filenamestart & vbnewline
message = message & "首页文件名:" & chr(9) & firstpage & vbnewline
message = message & "小图的宽度:" & chr(9) & imgw & vbnewline
message = message & "小图的高度" & chr(9) & imgh & vbnewline
message = message & "每行的图像数:" & chr(9) & wn & vbnewline
message = message & "行数:" & chr(9) & chr(9) & hn & vbnewline
message = message & vbnewline & "确定生成吗?" & vbnewline
dim StartRun
StartRun = msgbox(message,1,"VBS相册生成脚本")
if StartRun=1 then
CreatPageHtml(FileInofList(cpath))
end if
function FileInofList(cpath)
ON ERROR RESUME NEXT
dim FileNameListStr
FileNameListStr=""
filesize = 0
if fsoBrowse.FolderExists(cpath)then
Set theFolder=fsoBrowse.GetFolder(cpath)
Set theFiles=theFolder.Files
For Each x In theFiles
if right(lcase(x.name),4) = ".gif" or right(lcase(x.name),4) = ".png" or right(lcase(x.name),4) = ".jpg" then
if x.Size>0 then
set qswh=new qswhImg
arr=qswh.getimagesize(cpath & "\" & x.name)'取得图片的扩展名,高宽信息
dim imgext,imgWidth,imgheight
imgext = arr(0)
imgWidth = arr(1)
imgheight = arr(2)
if lcase(imgext) = "gif" or lcase(imgext) = "jpg" or lcase(imgext) = "png" then
FileNameListStr = FileNameListStr & x.name & "|"& x.Size &"|"& imgWidth & "|" & imgheight &"***"
end if
end if
end if
next
end if
set fsoBrowse = nothing
if len(FileNameListStr)>3 then
FileNameListStr = left(FileNameListStr,len(FileNameListStr)-3)
end if
FileInofList = FileNameListStr
if err<>0 then
msgbox "FileInofList 出错了:" & err.description
err.clear
end if
end function
sub CreatPageHtml(ListStr)
ON ERROR RESUME NEXT
dim filenamearr,filenamenum,outstr
filenamearr = split(ListStr,"***")
filenamenum = ubound(filenamearr)
outstr = ""
for a = 0 to filenamenum
thisstr = filenamearr(a)
thisstrarr = split(thisstr,"|")
if ubound(thisstrarr) = 3 then
dim w,h
w = thisstrarr(2)
h = thisstrarr(3)
okw = imgw
okh = imgh
if (w/h)>(imgw/imgh) then
if int(w)>=int(imgw) then
okw = imgw
okh = formatnumber(h*imgw/w,0)
else
okw = w
okh = h
end if
else
if int(h)>=int(imgh) then
okh = imgh
okw = formatnumber(w*imgh/h,0)
else
okw = w
okh = h
end if
end if
dim vspace
vspace = 0
if int(imgh)>int(okh) then
vspace = formatnumber((imgh-okh)/2,0)-3
end if
if int(vspace)<1 then
vspace = 0
end if
outstr = outstr & "
end if
if ((a+1) mod pagesize = 0) or (a = filenamenum) then
dim n1,nn
n1 = formatnumber(((a+1)/pagesize+0.49999),0)
nn = formatnumber((filenamenum+1)/pagesize+0.49999,0)
pagestr = "
else
pagestr = ""
end if
if int(n1) = 1 and firstpage<>"" then
creatfile outstr,pagestr,"/"& firstpage
else
creatfile outstr,pagestr,"/"& filenamestart &""& addzero(n1,nn) &".htm"
end if
outstr = ""
end if
next
if err=0 then
msgbox "文件已生成"
else
msgbox "CreatPageHtml 出错了:" & err.description
err.clear
end if
end sub
function addzero(num1,numn)
addzero = right("00000000"&num1,len(numn))
end function
function formattitle(str)
str1 = str
str1 = replace(str1,"""",""")
formattitle = str1
end function
sub creatfile(outstr,pagestr,name)
ON ERROR RESUME NEXT
dim tmphtml
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & ""& pagetitle &" " & vbNewLine
tmphtml = tmphtml & "
用到的技术:Scripting.FileSystemObject,Adodb.Stream。其中得到图片长宽用了秋水无恨的Adodb.Stream取得图像的高宽
复制代码 代码如下:
'///////////////////////////////////////////////
'VBS相册生成脚本,使用方法:将此文件放在sendto目录中(在运行中输入直接sendto,就可以打开),然后在有图片的文件夹上点右键,选择发送到,等一下,就OK了。
'海娃 http://www.51windows.Net
'更新日期:2004-12-30
'///////////////////////////////////////////////
Set ArgObj = WScript.Arguments
Set fsoBrowse = CreateObject("Scripting.FileSystemObject")
dim cpath,imgw,imgh,pagesize,wn,hn,pagetitle,filenamestart,firstpage
cpath=ArgObj(0)'传递路径
imgw = 240
imgh = 180
wn = 3
hn = 3
pagetitle = "图片展示 - 51windows.Net"
filenamestart = "Page_"
firstpage = "index.htm"
pagetitle2 = inputbox("请输入页面标题","请输入页面标题",pagetitle)
if isempty(pagetitle2) = false and len(pagetitle2) > 1 then
pagetitle = pagetitle2
end if
filenamestart2 = inputbox("请输入文件名前缀","请输入文件名前缀",filenamestart)
if isempty(filenamestart2) = false and len(filenamestart2) > 1 then
filenamestart = filenamestart2
end if
firstpage2 = inputbox("请输入第一页的文件名,点取消按序号生成","请输入第一页的文件名",firstpage)
if isempty(firstpage2) = false and len(filenamestart2) > 1 then
firstpage = firstpage2
else
firstpage = ""
end if
if len(firstpage) > 0 and (right(lcase(firstpage),4)<>".htm" and right(lcase(firstpage),5)<>".html") then
firstpage = firstpage & ".htm"
end if
imgw2 = inputbox("请输入小图的宽度","请输入小图的宽度",imgw)
if isnumeric(imgw2) and isempty(imgw2) = false then
imgw = imgw2
end if
imgh2 = inputbox("请输入小图的高度","请输入小图的高度",imgh)
if isnumeric(imgh2) and isempty(imgh2) = false then
imgh = imgh2
end if
wn2 = inputbox("请输入每行的图像数","请输入每行的图像数",wn)
if isnumeric(wn2) and isempty(wn2) = false then
wn = wn2
end if
hn2 = inputbox("请输入行数","请输入行数",hn)
if isnumeric(hn2) and isempty(hn2) = false then
hn = hn2
end if
dim info
info = ""
pagesize = wn*hn
dim message
message = ""
message = message & "文件路径:" & chr(9) & cpath & vbnewline
message = message & "页面标题:" & chr(9) & pagetitle & vbnewline
message = message & "文件名前缀:" & chr(9) & filenamestart & vbnewline
message = message & "首页文件名:" & chr(9) & firstpage & vbnewline
message = message & "小图的宽度:" & chr(9) & imgw & vbnewline
message = message & "小图的高度" & chr(9) & imgh & vbnewline
message = message & "每行的图像数:" & chr(9) & wn & vbnewline
message = message & "行数:" & chr(9) & chr(9) & hn & vbnewline
message = message & vbnewline & "确定生成吗?" & vbnewline
dim StartRun
StartRun = msgbox(message,1,"VBS相册生成脚本")
if StartRun=1 then
CreatPageHtml(FileInofList(cpath))
end if
function FileInofList(cpath)
ON ERROR RESUME NEXT
dim FileNameListStr
FileNameListStr=""
filesize = 0
if fsoBrowse.FolderExists(cpath)then
Set theFolder=fsoBrowse.GetFolder(cpath)
Set theFiles=theFolder.Files
For Each x In theFiles
if right(lcase(x.name),4) = ".gif" or right(lcase(x.name),4) = ".png" or right(lcase(x.name),4) = ".jpg" then
if x.Size>0 then
set qswh=new qswhImg
arr=qswh.getimagesize(cpath & "\" & x.name)'取得图片的扩展名,高宽信息
dim imgext,imgWidth,imgheight
imgext = arr(0)
imgWidth = arr(1)
imgheight = arr(2)
if lcase(imgext) = "gif" or lcase(imgext) = "jpg" or lcase(imgext) = "png" then
FileNameListStr = FileNameListStr & x.name & "|"& x.Size &"|"& imgWidth & "|" & imgheight &"***"
end if
end if
end if
next
end if
set fsoBrowse = nothing
if len(FileNameListStr)>3 then
FileNameListStr = left(FileNameListStr,len(FileNameListStr)-3)
end if
FileInofList = FileNameListStr
if err<>0 then
msgbox "FileInofList 出错了:" & err.description
err.clear
end if
end function
sub CreatPageHtml(ListStr)
ON ERROR RESUME NEXT
dim filenamearr,filenamenum,outstr
filenamearr = split(ListStr,"***")
filenamenum = ubound(filenamearr)
outstr = ""
for a = 0 to filenamenum
thisstr = filenamearr(a)
thisstrarr = split(thisstr,"|")
if ubound(thisstrarr) = 3 then
dim w,h
w = thisstrarr(2)
h = thisstrarr(3)
okw = imgw
okh = imgh
if (w/h)>(imgw/imgh) then
if int(w)>=int(imgw) then
okw = imgw
okh = formatnumber(h*imgw/w,0)
else
okw = w
okh = h
end if
else
if int(h)>=int(imgh) then
okh = imgh
okw = formatnumber(w*imgh/h,0)
else
okw = w
okh = h
end if
end if
dim vspace
vspace = 0
if int(imgh)>int(okh) then
vspace = formatnumber((imgh-okh)/2,0)-3
end if
if int(vspace)<1 then
vspace = 0
end if
outstr = outstr & "
" & vbnewline
outstr = outstr & " " & vbnewline
outstr = outstr & " " & vbnewline
outstr = outstr & "
" & vbnewline outstr = outstr & " " & vbnewline
outstr = outstr & " " & vbnewline
outstr = outstr & "
end if
if ((a+1) mod pagesize = 0) or (a = filenamenum) then
dim n1,nn
n1 = formatnumber(((a+1)/pagesize+0.49999),0)
nn = formatnumber((filenamenum+1)/pagesize+0.49999,0)
pagestr = "
"
if int(pagesize) = 1 then
nn = int(nn)+1
end if
for b = 1 to nn
bb = addzero(b,nn)
if int(b)<>int(n1) then
if int(b) = 1 and firstpage<>"" then
pagestr = pagestr & " "& bb &" "
else
pagestr = pagestr & " "& bb &" "
end if
else
pagestr = pagestr & " "& bb &" "
end if
next
pagestr = pagestr & "
if int(pagesize) = 1 then
nn = int(nn)+1
end if
for b = 1 to nn
bb = addzero(b,nn)
if int(b)<>int(n1) then
if int(b) = 1 and firstpage<>"" then
pagestr = pagestr & " "& bb &" "
else
pagestr = pagestr & " "& bb &" "
end if
else
pagestr = pagestr & " "& bb &" "
end if
next
pagestr = pagestr & "
"
if int(n1) = 1 then
pagestr = pagestr & "[ Prev ]"
else
if int(n1) = 2 and firstpage<>"" then
pagestr = pagestr & "[ Prev ]"
else
pagestr = pagestr & "[ Prev ]"
end if
end if
if int(n1) = int(nn) then
pagestr = pagestr & "[ Next ]"
else
pagestr = pagestr & "[ Next ]"
end if
if int(nn) > 1 then
pagestr = "
" if int(n1) = 1 then
pagestr = pagestr & "[ Prev ]"
else
if int(n1) = 2 and firstpage<>"" then
pagestr = pagestr & "[ Prev ]"
else
pagestr = pagestr & "[ Prev ]"
end if
end if
if int(n1) = int(nn) then
pagestr = pagestr & "[ Next ]"
else
pagestr = pagestr & "[ Next ]"
end if
if int(nn) > 1 then
pagestr = "
"& pagestr & "
else
pagestr = ""
end if
if int(n1) = 1 and firstpage<>"" then
creatfile outstr,pagestr,"/"& firstpage
else
creatfile outstr,pagestr,"/"& filenamestart &""& addzero(n1,nn) &".htm"
end if
outstr = ""
end if
next
if err=0 then
msgbox "文件已生成"
else
msgbox "CreatPageHtml 出错了:" & err.description
err.clear
end if
end sub
function addzero(num1,numn)
addzero = right("00000000"&num1,len(numn))
end function
function formattitle(str)
str1 = str
str1 = replace(str1,"""",""")
formattitle = str1
end function
sub creatfile(outstr,pagestr,name)
ON ERROR RESUME NEXT
dim tmphtml
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & "" & vbNewLine
tmphtml = tmphtml & "
tmphtml = tmphtml & "
