Scripting Gallery

Batch Photoshop Gallery Generator

Scripting Gallery

Modification

What if you want to extend functionality of the Scripting Gallery script to meet requirements of your current specific task (e.g. creating some hierarchical folder tree based on the number of processed files and the current chakra flow, or processing files according to their names, etc.)? You definitely can do this! (Not sure for the chakra flow though.)

Vbscript and Photoshop has all functionality you may need. And you're free to modify the source code of the script (under the terms of the GNU General Public License).

So let me guide you through the basic workflow of the script and list the global variables, objects and routines you may find useful to refer to in your own code.

Workflow

The basic script workflow can be thought of as sequence of stages (not surprisingly), each performing its own task and dealing mostly with it's own routines (yet closely communicating with each other by routine calls and through the global variables). While examine the source code, you'll find it divided in sections by special commentaries blocks used for separating one stage from another.

So, let's roll.

  1. User is asked to input various settings. Input data is then processed (if necessary) to fit according variable types. This is the section "Start (preparing data)" in source code.

  2. Script is then form the list of all image files found in specified initial directory and its subfolders (if NestedDirs is set to true). Most of the routines of this stage can be found in section "Service routines".

  3. Initializing Photoshop and its settings, opening frame and logo images. This section is called "Working with Photoshop" in source code. And here's where the fun begins. In loop script sequentially accesses each file in list (formed on previous stage) and launches PerformAction routine, which is responsible for opening current file, saving its parameters (width, height, aspect ratio) in global variables, and, finally, launching routines for creating "Big" images (stages 4,5) and thumbnails (stages 6,7). It is also responsible for creating directories in current file's folder for storing there output files. After all of the following stages completed, all opened files are closed and Photoshop initial settings are restored.

    Hint: file system specific tasks (e.g. creating the specifc folder based on the name of currently processing image) is supposed to be put in this section.

  4. Creating "Big" images, part 1 (section "Creating Bigs - Init"). Routine CreateBigs forms the store path and name of "Big" output image and launches the BigGenerator routine.

    Hint: there is some commented code-parts in this section, which are (if uncommented) modifies the creating "Big" images process so that logo position is set according to source image's aspect ratio.

    Hint: specific settings substitution and redefinition for creating "Big" images are supposed to be put in this section. Also, if you want to create images with several different sizes just call BigGenerator here for several times passing appropriate settings as parameters.

  5. Creating "Big" images, part 2 (section "Creating Bigs - Generating"). BigGenerator routine accepts all parameters needed for creating the desired "Big" image as arguments and, finally, creates output image and saves it to output folder.

    Hint: specific image-processing algorithm changes for creating "Big" images (e.g. image transformation, filter applying, etc.) are supposed to be put in this section.

  6. Creating thumbnails, part 1 (section "Creating thumbnails - Init"). Launches if WorkMode is set to 1. CreateThumbs forms the store path and name of output thumbnail image, decides which width and height of thumbnail to use (based on ThumbDifferent setting) and launches the ThumbnailGenerator routine.

    Hint: there is some commented code-parts in this section, which are (if uncommented) modifies the creating thumbnails process so that vertical indent ThumbDy is applied only for "vertical" source images, e.g. images with aspect ratio > 1.

    Hint: specific settings substitution and redefinition for creating thumbnails are supposed to be put in this section. Also, if you want to create thumbnails with several different sizes just call ThumbnailGenerator here for several times passing appropriate settings as parameters.

  7. Creating thumbnails, part 2 (section "Creating thumbnails - Generating"). ThumbnailGenerator routine accepts all parameters needed for creating the desired thumbnails as arguments and, finally, creates output thumbnail and saves it to output folder.

    Hint: specific image-processing algorithm changes for creating thumbnails (e.g. image transformation, filter applying, etc.) are supposed to be put in this section.

Global variables

Here's the list of global variables (in addition to global script settings) you can refer to from your code at runtime.

Files [Array]
Array of image files full names (file path + file name) in script queue
appRef [Object]
Photoshop Application object (see Photoshop Scripting Guide which came with Photoshop for details)
docRef [Object]
Photoshop object of currently processing image file opened in Photoshop
docLogoRef [Object]
Photoshop object of logo image file opened in Photoshop
docFrameRef [Object]
Photoshop object of frame image file opened in Photoshop
docFrameRef_Horiz [Object]
Photoshop object of frame image file for images with aspect ratio (AR) <= 1 (works if ThumbDifferent is set to true) opened in Photoshop
originalState [Object]
Photoshop History State object used for storing the original history state of newly opened image in order to refer to before creating thumbnails
exportOptions [Object]
Photoshop Export Options object used for storing export settings for output images (see Photoshop Scripting Guide for details)
jpgSaveOptions [Object]
Photoshop JPG Save Options object used for storing "Save As" settings for output images (see Photoshop Scripting Guide for details)
cnt [Integer]
Number of currently processing file and its position in Files array added by 1
fileFullName [String]
Full name of currently processing file (e.g. file path + file name)
fileName [String]
Name of currently processing file
filePath [String]
Path to the home folder of currently processing file
newFileName [String]
New file name currently processing file gets if Rename setting is ste to true
Width [Integer]
Width of currently processing image file
Height [Integer]
Height of currently processing image file
AR [Integer]
Aspect ratio (AR = Height / Width) of currently processing image
fso [Object]
Windows Script Host File System Object used for manipulating with file system objects (folders and files)
ScriptPath [String]
Path to the home directory of the script (it is default value for Path setting described in Configuration section)

Routines

Here's the list of some of useful routines (more to be found in the source code in appropriate section) you may call from your code at runtime.

Service routines

Function ListFiles (Path, NestedDirs)
Function that accepts path to the directory (Path) and NestedDirs bollean parameter (defines whether it should dive into subfolders) and returns the list of files (array of their full filenames) found in specified folder.
Function IsGraphicFile (Name)
Function that accepts file name (Name) and returns boolean whether it is graphic file (one with extension .jpg, .jpeg, .bmp, .png, .tif, .tiff, .gif) or not.
Function GetFileName (FullName)
Function that accepts file full name (path + file name, e.g. "c:\directory\file.jpg"; FullName) and returns string containing file name (e.g. "file.jpg").
Function ExcludeFileExtension (Name)
Function that accepts file name (e.g. "file.jpg"; Name) and returns string containing file name without extension (e.g. "file").
Function GetFilePath (FullName)
Function that accepts file full name (path + file name, e.g. "c:\directory\file.jpg"; FullName) and returns string containing path to the file (e.g. "c:\directory\").
Function GetNewEnumeratorName (i, digs, prefix)
Function that accepts positive integer i (counter value), number of digits digs, file name prefix prefix (e.g. GetNewEnumeratorName(3, 2, "g")) and returns string composed of passed parameters (e.g. "g03"). Used for renaming output files with counter value.
Function AddTrailingSlash (p)
Function that accepts path p (e.g. "c:\dummy\path" or "c:\dummy\path\") and returns string containing path with added trailing slash (if needed; e.g. "c:\dummy\path\").
Sub CreateFolders (parentPath)
Subroutine that accepts path to a directory parentPath (e.g. "c:\dummy\path" or "c:\dummy\path\") and creates subfolders inside it with names specified in b_Folder and s_Folder global parameters (if needed).

Working with Photoshop

Sub Photoshopping
Subroutine that backs up Photoshop preferences (and restores them in the end) and loops through the list of files (Files global array) and launches PerformAction routine.
Sub PrepareExportSettings
Subroutine that prepares export settings for output files according to global settings of the script.
Sub PerformAction (i)
Subroutine that opens currently processing file (specified by its order number i in Files global array), saves its parameters (width, height, aspect ratio) in global variables, and, finally, launches routines for creating "Big" images and thumbnails.

Creating Bigs - Init

Sub CreateBigs (i)
Subroutine that forms the store path and name of "Big" output image of currently processing file (specified by its order number i in Files global array) and launches the BigGenerator routine.

Creating Bigs - Generating

Sub BigGenerator (bResizeMode, bSize, path, fname, docLogoRef)
Subroutine that accepts all parameters needed for creating the desired "Big" image as arguments and, finally, creates output image and saves it to output folder.
  • bResizeMode is for ResizeMode parameter of the script (see Configuration for details)
  • bSize is for Size parameter of the script (see Configuration for details)
  • path is for path to output folder for "Big" image
  • fname is for output file name of "Big" image
  • docLogoRef is for referencing Photoshop object of logo image file opened in Photoshop

Creating thumbnails - Init

Sub CreateThumbs (i)
Subroutine that forms the store path and name of output thumbnail image of currently processing file (specified by its order number i in Files global array), decides which width and height of thumbnail to use (based on ThumbDifferent setting) and launches the ThumbnailGenerator routine.

Creating thumbnails - Generating

Sub ThumbnailGenerator (tThumbWidth, tThumbHeight, scaleFactor, tThumbDy, path, fname, frameRef)
Subroutine that accepts all parameters needed for creating the desired thumbnails as arguments and, finally, creates output thumbnail and saves it to output folder.
  • tThumbWidth is for ThumbWidth (or ThumbWidth_Horiz) parameter of the script (see Configuration for details); defines the width of thumbnail
  • tThumbHeight is for ThumbHeight (or ThumbHeight_Horiz) parameter of the script (see Configuration for details); defines the height of thumbnail
  • scaleFactor is for ThumbScaleFactor parameter of the script (see Configuration for details)
  • tThumbDy is for ThumbDy parameter of the script (see Configuration for details)
  • path is for path to output folder for thumbnail
  • fname is for output file name of thumbnail
  • frameRef is for referencing Photoshop object of frame image file opened in Photoshop