Note: all scripts examples included in these Web pages are absolutely free. You can copy, use, and modify these scripts anyway you want. The scripts are published without warranty of any kind.
This VBScript example builds the index files of images located in some directory. The script does the following:
|
File index.vbs
View result |
'The directory where we get the files from
source_dir="d:\test"
'Prefix of resulting index file. The script will add <number>.jpg
'to this prefix
target_file="d:\jpg\index"
'Maximal horizontal image size in the preview
max_xsize=120
'Maximal vertical image size in the preview
max_ysize=90
'Vertical size of place for filename text
text_vertical=15
'maximal number of columns in the index image
files_in_row=3
'maximal number of rows in the index image
max_rows_count=4
'the space between images
cellpadding=10
Set fs=CreateObject("Scripting.FileSystemObject")
Set g=CreateObject("shotgraph.image")
Set fld=fs.GetFolder(source_dir)
Set files=fld.Files
Dim names()
cnt=-1
for each f in files
t=g.GetFileDimensions(source_dir&"\"&f.name,x,y)
if t>0 then
cnt=cnt+1
ReDim preserve names(cnt)
names(cnt)=f.name
end if
Next
blocksize=files_in_row*max_rows_count
for j=0 to cnt step blocksize
if j+blocksize>cnt then cnt2=cnt-j else cnt2=blocksize-1
rows=cnt2\files_in_row+1
if (cnt2+1>files_in_row) then columns=files_in_row else columns=cnt2+1
xsize=cellpadding+columns*(max_xsize+cellpadding)
ysize=cellpadding+rows*(max_ysize+cellpadding+text_vertical)
'We do not care about palette size because we are exporting to Jpeg
'Only drawing colors should be declared
g.CreateImage xsize,ysize,8
'Background color
g.SetColor 0,51,51,255
'Text color
g.SetColor 1,255,255,255
g.SetBgColor 0
g.SetTextColor 1
g.FillRect 0,0,xsize-1,ysize-1
g.CreateFont "Arial",0,12,0,False,False,False,False
g.SetTextAlign "TA_LEFT","TA_BOTTOM"
g.SetBkMode "TRANSPARENT"
for i=0 to cnt2
column=i mod files_in_row
row=i\files_in_row
t=g.GetFileDimensions(source_dir&"\"&names(i+j),x,y)
if (x/max_xsize>y/max_ysize) then
x1=max_xsize
y1=y*max_xsize\x
else
y1=max_ysize
x1=x*max_ysize\y
end if
g.InitClipboard x,y
g.SelectClipboard True
g.ReadImage source_dir&"\"&names(i+j),pal,0,0
xdest=cellpadding+column*(max_xsize+cellpadding)
ydest=cellpadding+row*(max_ysize+cellpadding+text_vertical)
xtext=xdest
ytext=ydest+max_ysize+text_vertical
g.Stretch xdest,ydest,x1,y1,0,0,x,y,"SRCCOPY","HALFTONE"
g.SelectClipboard False
g.TextOut xtext,ytext,names(i+j),True
Next
g.JpegImage 75,0,target_file&(j\blocksize+1)&".jpg"
Next
|