Create thumbnails with photoshop.

This script uses photoshop cs3 to create thumbnails from jpg images. A thumbnail directory will be created in the same directory where the images are. The thumbnails will be saved with the same name as the original image. The directory name is an argument on the command line. To start the script type:

cscript CreThumbs.vbs c:\images
'*****************************************************************
'** Script: CreThumbs.vbs
'** Version: 1.0
'** Created: 12/29/2008 9:51PM
'** Author: Adriaan Westra
'** E-mail: 
'** Purpose / Comments:
'** Create thumbnails for images
'**
'**
'** Changelog :
'** 29-12-2008 9:37 : Initial version
'**
'*****************************************************************

Dim Version : Version = "1.0" ' Script version
Dim Author : Author = "Adriaan Westra"
Dim Email : Email = ""
Dim appPhotoshop
Dim objImage
Dim strFileName

'*****************************************************************
'** Add Error Handling
on error resume Next

'*****************************************************************
'** Make sure the script is started with cscript
If InStr(wscript.FullName, "wscript.exe") > 0 Then
MsgBox "Please run this script with cscript.exe." & Chr(13) & _
"For example : cscript " & WScript.ScriptName & " /?", _ 
vbExclamation, WScript.ScriptName
WScript.Quit(1)
End If

'*****************************************************************
'** Get commandline parameters
Set Args = Wscript.Arguments

If Args.Count = 0 Then
	strImageDir = InputBox("Please give the directory name " & _
	"to process : ",wscript.scriptname, strPath)
Else
   If InStr(Args(0),"/?") > 0 Or InStr(UCase(Args(0)),"/H") > 0 _ 
   Or InStr(UCase(Args(0)),"/HELP") > 0 Then
      DisplayHelp
      Wscript.quit(0)
   Else
      strImageDir = Args(0)
   End if
End if

'*****************************************************************
'** Get startup path from scriptfullname
Pos = InStr(wscript.ScriptFullName, wscript.ScriptName)
strPath = Mid(wscript.ScriptFullName,1,Pos - 1)
'*****************************************************************
'** Create output directory
strOutputDir = strImageDir & "\thumbnails"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not (objFSO.FolderExists(strOutputDir)) Then
   Set objOutDir = objFSO.CreateFolder(strOutputDir)
End If


'*****************************************************************
'** Open Photoshop
Set appPhotoshop = CreateObject( "Photoshop.Application" )
appPhotoshop.BringToFront
appPhotoshop.DisplayDialogs = 3 ' psDisplayNoDialogs
'*****************************************************************
'** Process directory
Set objImgDir = objFSO.GetFolder(strImageDir)
For each objFile in objImgDir.Files
'*****************************************************************
'** If file is jpg image then Create thumbnail
   If IsJPG(objFile.Name) Then
      
      strFileName = strImageDir & "\" & objFile.name
'*****************************************************************
'** Open the file in Photoshop  
      Set objImage = appPhotoshop.Open( strFileName )
      nWidth = objImage.width / 18.6
      nHeight =  objImage.height / 18.6

'*****************************************************************
'** Resize the image
      objImage.ResizeImage nWidth,nHeight, 240,4
      
'*****************************************************************
'** Set jpg options
      Set jpgSaveOptions = CreateObject( "Photoshop.JPEGSaveOptions" )
      jpgSaveOptions.EmbedColorProfile = True
      jpgSaveOptions.FormatOptions = 1 ' psStandardBaseline
      jpgSaveOptions.Matte = 1 ' psNoMatte
      jpgSaveOptions.Quality = 12
      outFileName = strOutputDir  & "\" & objFile.name
'*****************************************************************
'** Save the thumbnail
      objImage.SaveAs outFileName, jpgSaveOptions, True, extType
'*****************************************************************
'** Close image
      objImage.close(2)
   End If
Next
'*****************************************************************
'** Close Photoshop
appPhotoshop.Quit


'*****************************************************************
'** End script
Wscript.Quit()

'*****************************************************************
'** Sub: DisplayHelp
'** Version: 1.0
'** Created: 24-03-2003 8:22
'** Author: Adriaan Westra
'** E-mail: 
'**
'** Purpose / Comments:
'** Display help for script
'**
'** Arguments :
'**
'** Wijzigingslog :
'** 24-03-2003 8:22 : InitiŽle versie
'**
'*****************************************************************
Sub DisplayHelp()
   strComment = string(2,"*")
   strCmntLine = String(79, "*") 
   wscript.echo strCmntline
   wscript.echo strComment
   wscript.echo strComment & " Online help for " & _ 
      Wscript.scriptname & " version : " & Version
   wscript.echo strComment
   wscript.echo strComment & " Usage : cscript " & _ 
      Wscript.scriptname & " directoryname"
   wscript.echo strComment
   wscript.echo strComment & " Purpose : Create thumbnails " & _
    "for all images in given directory"
   wscript.echo strComment
   wscript.echo strComment & " Author : " & Author
   wscript.echo strComment & " E-mail : " & Email
   wscript.echo strComment
   wscript.echo strCmntline
End Sub
'*****************************************************************
'** Function: IsJPG
'** Version: 1.0
'** Created: 12/29/2008 11:01PM
'** Author: Adriaan Westra
'** E-mail: 
'**
'** Purpose / Comments:
'** Determine if file is jpg image
'**
'** Arguments :
'** strFilename : name of the file to check 
'** 
'** Wijzigingslog :
'** 12/29/2008 11:02PM : InitiŽle versie
'**
'*****************************************************************
Function IsJPG(strFilename)
   Set objRegExp = New RegExp
   objRegExp.Pattern = "\w.jpg"
   objRegExp.IgnoreCase = True
   IsJPG = objRegExp.Test(strFileName)
End Function