Photoshop Automation: VBScript for Batch Image Resizing

Looking for an easy way to batch resize images in Photoshop? I recently learned Photoshop VBScripting and created a simple script that automatically generates blog thumbnails. This Photoshop automation script saves me hours of manual resizing work and can even add custom elements like map markers to images.

Why Use Photoshop Automation for Image Resizing?

As bloggers, we often need consistent thumbnail sizes across our websites. Manual resizing is tedious and time-consuming. With this Photoshop batch resize script, you can process dozens or hundreds of images in seconds while maintaining quality and consistency.

How the Photoshop VBScript Works

The script scans your folder for JPG images and resizes them according to your specifications. It creates new thumbnail versions with a custom suffix while preserving your originals.

Customizing Your Photoshop Batch Resize Settings

You can easily modify these script settings using any text editor like Notepad:

SettingFunction
RESIZEWIDTHSets the thumbnail width in pixels
RESIZEHEIGHTSets the thumbnail height in pixels
IGNOREVERTICALOption to skip portrait-oriented images
SUFFIXText added to filename of resized images

Using the Photoshop Automation Script

Implementation is straightforward:

  1. Download the script file
  2. Place it in the folder with your images (backup your images first!)
  3. Double-click to execute
  4. Wait for the “Complete” message

The VBScript Code for Photoshop Image Resizing

Here’s the complete batch resize script for Photoshop automation:

Public Const RESIZEWIDTH = 150
Public Const RESIZEHEIGHT = 113

Public Const IGNOREVERTICAL = True
Public Const SUFFIX = "-th"

Dim spath
spath = Mid(WScript.ScriptFullName, 1, InStrRev(WScript.ScriptFullName, "\", -1, vbBinaryCompare))

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim foldero
Set foldero = fso.GetFolder(spath)

Dim fileo
Dim sfile

For Each fileo In foldero.Files
'only modify jpg files
sfile = fileo.Name
If InStrRev(sfile, ".jpg", -1, vbTextCompare) = Len(sfile) - 3 Then
resize spath & sfile
End If
Next

MsgBox "Complete."

Sub resize(sfilename)

Set WshShell = WScript.CreateObject("WScript.Shell")
Set colProcessList = GetObject("Winmgmts:").ExecQuery("Select * from Win32_Process")

Dim found
found = False

For Each objProcess In colProcessList
If StrComp(objProcess.Name, "photoshop.exe", vbTextCompare) = 0 Then
found = True
Exit For
End If
Next

Dim appRef
If found Then
Set appRef = GetObject(, "Photoshop.Application")
Else
Set appRef = CreateObject("Photoshop.Application")
End If

Do While appRef.documents.Count
appRef.activeDocument.Close 2 'dont' save
Loop

Dim originalRulerUnits
originalRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = 1 'pixels

Dim docRef
Set docRef = appRef.Open(sfilename)

Dim modified
modified = False

If docRef.Width >= docRef.Height Then 'horizontal photo
If docRef.Width <> RESIZEWIDTH Then 'proceed if not already resized
docRef.ResizeImage RESIZEWIDTH 'preserves aspect ratio
modified = True
End If
Else 'verticle photo
If Not IGNOREVERTICAL Then 'proceed
If docRef.Height <> RESIZEHEIGHT Then 'proceed if not already resized
docRef.ResizeImage , RESIZEHEIGHT 'preserves aspect ratio
modified = True
End If
End If
End If

If modified Then 'only save if the image was modified
Dim jpgSaveOptions
Set jpgSaveOptions = CreateObject("Photoshop.JPEGSaveOptions")
jpgSaveOptions.Quality = 8

'calculate the new file name
Dim newfilename
newfilename = Mid(sfilename, 1, Len(sfilename) - 4) & SUFFIX & ".jpg"

docRef.SaveAs newfilename, jpgSaveOptions, True, 2 'for psLowercase
End If

docRef.Close 2 'dont' save

appRef.Preferences.RulerUnits = originalRulerUnits

End Sub

Benefits of Photoshop Automation for Bloggers

This Photoshop VBScript has transformed my blogging workflow by:

  • Saving hours of manual image processing time
  • Ensuring consistent thumbnail dimensions across my site
  • Preserving original image files while creating optimized versions
  • Allowing customization for different image types and projects

For more advanced Photoshop automation techniques, check out Adobe’s official scripting documentation or explore Smashing Magazine’s guide to Photoshop scripting.

I wish I’d learned Photoshop scripting years ago. The time savings from automating repetitive tasks has been incredible.

Have you used VBScript for Photoshop automation? Share your experiences in the comments!