' ------------------------------------------------------------------------------------ ' SaveThumbnails.vbs ' Create thumbnail files that look like the thumbnails in MyAlbum ' ' This script will process all the selected pictures and will create a 3D looking ' thumbmnail file with a reduced picture in it a caption below. ' ------------------------------------------------------------------------------------ Option Explicit Const DT_TOP = &H0 ' Specifies top-justified text. Const DT_CENTER = &H1 ' Centers text horizontally. Const DT_NOPREFIX = &H800 ' Turns off processing of prefix characters. Const PS_SOLID = 0 ' Standard solid pen const THSIZE = 160 const BORDER = 5 const BOTTOMBORDER = 20 ' Enough for two lines of text const backColor = 12632256 ' Light Grey background (0xc0c0c0) const textColor = 255 ' Red text const textBkColor = -1 ' Transparent background const font ="Arial,16,0,400,0,0,0" dim alb, pic, fso, tempfolder, newFile, k, kPos, newPicTh, newPic, rect app.ClearTrace set alb = app.GetCurrentAlbum if not alb is nothing then Set fso = CreateObject("Scripting.FileSystemObject") ' Get a temporary file and set it with a BMP suffix to have a lossless storage Const TemporaryFolder = 2 Set tempfolder = fso.GetSpecialFolder( TemporaryFolder ) newFile = tempfolder.Path & "\" & fso.GetTempName k = instrrev( newFile, "." ) newFile = left( newFile, k ) & "bmp" const TYPE_BMP=1 const TYPE_JPEG=2 Dim nbPic, i nbPic = alb.nbVisiblePicture i = 0 while i < nbPic Set pic = alb.GetVisiblePicture(i) if pic.bSelected then app.Trace "Processing picture '" & pic.sShortFileName & "'..." ' Resize the picture in the temporary file kPos = alb.CvtNumPic( i, True ) app.trace " Creating temporary picture " & newFile if pic.ConvertAndResize( newFile, TYPE_BMP, THSIZE, THSIZE ) then set newPicTh = alb.AddPicture( newFile ) ' Create an empty new picture slightly larger than the new thumnail app.trace " Building the new thumbnail" set newPic = alb.NewPicture( newPicTh.w+2*BORDER, newPicTh.h+BORDER+BOTTOMBORDER, 32, backColor ) ' Draw a border and a shadow set rect = CreateObject("MyAlbum.rect") rect.x = 0 rect.y = 0 rect.w = newPic.w rect.h = newPic.h newPic.DrawRectangle rect, 0, 0, backColor, 0, 0, 0 newPic.DrawLine 1, 1, 1, newPic.h - 1, 0, PS_SOLID, 16777215 ' white line newPic.DrawLine 1, 1, newPic.w - 1, 1, 0, PS_SOLID, 16777215 ' white line newPic.DrawLine newPic.w - 2, 2, newPic.w - 2, newPic.h - 2, 0, PS_SOLID, 8421504 ' gray line newPic.DrawLine 2, newPic.h - 2, newPic.w - 1, newPic.h - 2, 0, PS_SOLID, 8421504 ' gray line ' Paste the current picture into the new one leaving a 5 pixel border newPicTh.copy 0 newPic.paste BORDER, BORDER ' Write the picture name at the bottom of the new picture rect.x = 0 rect.y = newPicTh.h + BORDER rect.w = newPicTh.w + 2 * BORDER rect.h = BOTTOMBORDER ' The caption is constructed with Display String used for the thumbnails newPic.drawText alb.ExpandMacro( pic, alb.sDSThumbnail ), rect, font, textColor, textBkColor, DT_TOP or DT_CENTER or DT_NOPREFIX ' Copy the whole picture to the clipboard newPic.copy(0) alb.DeletePicture newPic set newPic = Nothing alb.DeletePicture newPicTh set newPicTh = Nothing ' Now create a "real" picture with it's name derived from the original picture name app.trace " Creating the new thumbnail file" dim filename filename = pic.sFileName k = instrrev( filename, "." ) ' The new picture will have "_th" appended to its name and will be a JPEG picture filename = left( filename, k-1 ) & "_th.jpg" ' Paste the picture on the clipboard to a new picture and save it alb.paste filename ' The new picture is at the end of the album, move it next to the original picture alb.MovePicture alb.GetPicture( alb.nbPicture-1 ), kPos, True ' As a new picture has been added, increment the count nbPic = nbPic + 1 end if end if i = i + 1 wend alb.redraw app.Trace "Done !!!" end if