Photoshop Collage Automation via JavaScript

Collage Builder

These scripts are designed to build collage template files and to load images to these templates.   CollageBuilder.jsx is designed to build and scale template documents.   CollageLoader.jsx is designed to load user images into these templates.   LayerEffects.jsx is also provided to enable more layer effects options and to accommodate user actions.   It can be used before or after user images have been loaded into the template document.

The basic operation is to use CollageBuilder.jsx (Photoshop File:Scripts) to build a template with an optional large image and one or more columns and rows of smaller images.   During the template building operation, you can select the layout of the images and the layer styles or effects to be applied to each image.   This script is menu driven (intended for CS2) and has many options that will be described later.

A sample template is shown below.

The template consists of one uniquely named layer for each collage image.   You may also wish to add or remove layers, create an overall border or frame, add a copyright or logo, or add some text.   Save a copy of your completed template for use later.

Collage Loader

Once you have created and opened a template document, you are ready to run CollageLoader.jsx.   A file open dialog will be presented for each image placeholder (layer) found in the template.   The layers are named MainImage[xx] and smImage[xx].   Any other layers (including the default background layer) will be ignored and unchanged.

The file open dialog will depend on your OS (Windows or Mac).   You can elect to show the files with details, name only, or thumbnails.   The initial folder will default ([PSInstall]/Samples/), but the last folder navigated will be used again for subsequent opens.   The title text shows the layer name, orientation, and aspect ratio expected.   The layer names are also shown in the template image so you can easily see where the image is to be placed.   Once loaded, the layer name is changed to the image name.   You can quit at any time by simply canceling this dialog.   You can restart and the script will find only the remaining image placeholders.

Each image is re-sized (not cropped) to fit the dimensions of the current template layer as it is loaded.   The actual image aspect ratio is preserved.   It does not have to match the place holder aspect ratio.   The resized image will be centered in the current placeholder.   If the image background is transparent the layer effects will warp to fit.   This can create some interesting collages.

You might want to modify or replace the background layer, move or resize some of the image layers, or change some of the layer styles and effects at this time.   When finished, you should save this with a new file name.   You might also wish to flatten it to save what could be considerable disk space.

These scripts need to be installed to [PSInstall]/presets/scripts/.   Whenever new scripts are added here, Photoshop needs to be restarted to enable them.

Collage Builder Options

That wasn’t too difficult.   Now we should have a look at the options available in the Collage Builder menus.

The Cancel button simply exits the script.   The OK button will create a single layer template preview (faster) with guides and borders stroked or an actual layered template document.

If Preview Layout is checked a single layer preview is created.   Else a layered template is created.   If Dismiss Preview is checked the current preview will be discarded when a new preview or template is created.   There is space below these for a text message showing how many images are included and the time spent building the current preview or template.   Layered templates will take more time to build.

The rest of the menu is divided into panels for options related to the canvas, main image, small images, and Layer Styles or Layer Effects.

You can specify a desired canvas size (in inches), a canvas border, document resolution (PPI), and a default document name.   If Scale Canvas is checked, the document will be scaled to fit the images selected.   Else, the images will be scaled to fit the specified canvas size.   The Color Theme button is provided simply to allow changing the default template colors (background, main image, small images, and edge strokes).   This is not terribly important since the layer colors are discarded when the actual images are loaded.   But it can impact the preview operations.   For example, the Double Ring layer effect does not show well against a white background and the Drop Shadow effect does not show well against a black background.

The Main Image options include the size, border, and placement.   Usually the main image would be larger than the other (small) images.   It can be ignored completely by selecting the “none” Radio Button.   Else, simply decide where on the page you want it to be placed.   If you choose “middle” the small image rows and columns will wrap around the main image.   This will usually result in additional small images placed to retain symmetry as best as is possible.

The “Use background for main image” checkbox will create a background layer named “MainImage[xx]”.   In this case, the main image size and position will be used only to reserve an image area with no small image rows or columns.

The Secondary (small) Image options include the size and border and the number of rows and columns.   Rows and columns must be integer values, one or more.   Main image options may impose other restrictions.

The final panel includes options for selecting named Layer Styles or custom Layer Effects.   These include things like borders, drop shadow, and bevel and emboss.   There are five named layer styles.   Double Ring is a Photoshop default style.   The other four are simply named placeholders for styles you can create on your own.   This package includes four default styles that I have created simply to demonstrate how.   These are:

      CollageStyle1: Bevel & Emboss
      CollageStyle2: Inner Glow & Stroke
      CollageStyle3: Drop Shadow & black and white Color Overlay
      CollageStyle4: Inner Glow & Bevel & Emboss
If you wish to use these custom layer styles, they must be copied to the Photoshop styles folder, [PSInstall]/Presets/Styles/.   These samples are provided as CollageBuilderStyles.asl.   They must then be loaded in the PS Styles menu pallet.   Or you can create your own styles with these names.

The “Scale Styles” text input is used to scale the named styles.   The suggested scaling is based on the current small image size and assuming that the style properties were based on a 5x7 image at 300 PPI.   This is consistent with the Photoshop defaults.   You can define this scaling from 1 to 1,000 percent.   100% will invoke the default effects sizes.   If the selected Layer Style is “none”, the Scale Styles text input box is disabled.

If the selected Layer Style is “none”, the Layer Effects push button is enabled.   This will activate another menu where you may select or customize one or more layer effects.   The fundamental difference here between a Layer Style and a Layer Effect is that the layer styles are named collections of predefined effects.   The layer effects include the customizable options.   Thus they are employed via different menus in this script.

These panels allow you to select and combine various effects and tailor several options relevant to the particular effect.

Stroke Options include the stroke size in pixels, location, and the stroke color.

Color Overlay Options include the overlay opacity and color.

Drop Shadow Options include the angle, size, distance, spread, and color.

Bevel and Emboss Options include the depth, size, softening, shading angle, and shading altitude.

Glow Options include the color, inside or outside, opacity, size, and contour shape.

These layer effects are not scaled when they are applied.   Also, there are many effects options that are not included here.   And some other effects such as satin that have not been included.   But, any desired effects can always be saved as a named Photoshop layer style.

Layer Effects Options

The LayerEffects script can be run against a template or a collage that includes processsed images.   The options are described here: Layer Effects.  


These scripts are provided as shareware with no warranty, but also no usage restrictions.   You are free to use and modify them.   If you feel obliged to pay something, make a contribution to your favorite charity.   The sample scripts are available at this link in a ZIP file   These have been tested under Windows and Mac systems with CS2 and CS3.  

If you have any comments, or suggestions, I would welcome your input.   Please send me an  Email.

Rags Gardner
Rags Int., Inc.
204 Trailwood Drive
Euless, TX 76039
(817) 267-2554
Send Email
May 29, 2006
June 7, 2006
February 29, 2008

This page last updated on: Friday February 29 2008
You are visitor number 57,599 since 05/30/06