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.
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.Script is then form the list of all image files found in specified initial directory and its subfolders (if
NestedDirs
is set totrue
). Most of the routines of this stage can be found in section "Service routines
".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 launchesPerformAction
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.
Creating "Big" images, part 1 (section "
Creating Bigs - Init
"). RoutineCreateBigs
forms the store path and name of "Big" output image and launches theBigGenerator
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.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.
Creating thumbnails, part 1 (section "
Creating thumbnails - Init
"). Launches ifWorkMode
is set to1
.CreateThumbs
forms the store path and name of output thumbnail image, decides which width and height of thumbnail to use (based onThumbDifferent
setting) and launches theThumbnailGenerator
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.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 totrue
) 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 totrue
- 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
) andNestedDirs
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 digitsdigs
, file name prefixprefix
(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 inb_Folder
ands_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 launchesPerformAction
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
inFiles
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
inFiles
global array) and launches theBigGenerator
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 forResizeMode
parameter of the script (see Configuration for details)bSize
is forSize
parameter of the script (see Configuration for details)path
is for path to output folder for "Big" imagefname
is for output file name of "Big" imagedocLogoRef
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
inFiles
global array), decides which width and height of thumbnail to use (based onThumbDifferent
setting) and launches theThumbnailGenerator
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 forThumbWidth
(orThumbWidth_Horiz
) parameter of the script (see Configuration for details); defines the width of thumbnailtThumbHeight
is forThumbHeight
(orThumbHeight_Horiz
) parameter of the script (see Configuration for details); defines the height of thumbnailscaleFactor
is forThumbScaleFactor
parameter of the script (see Configuration for details)tThumbDy
is forThumbDy
parameter of the script (see Configuration for details)path
is for path to output folder for thumbnailfname
is for output file name of thumbnailframeRef
is for referencing Photoshop object of frame image file opened in Photoshop
Social Tools