Manipulating Many Images at Once Using Photoshop, GIMP, ImageMagick, PIL and OpenCV: Photoshop (Part 2 of 6)

This is part 2 of 6 of a mini-series of posts that discuss how to manipulate many images at once (instead of individually) using a variety of techniques. Please refer to part 1 of 6 for more information.

This post explores how to batch process images in Adobe Photoshop. We will resize and apply the sepia tone effect to a group of photos. For resizing, each image is scaled to three (3) different sizes, 75%, 50%, 25%, of the original. The sepia tone effect is achieved with image desaturation and blending using the algorithm discussed in the introductory post.

All code on this page was developed with & tested against Adobe Photoshop CC 2015.

Batch Processing in Photoshop

Photoshop offers two ways to process images in batch:

  • Batch accessible via File -> Automate -> Batch…
  • Image Processor accessible via File -> Scripts -> Image Processor…

Batch and Image Processor are almost identical in functionality, except Batch requires an Action while for the Image Processor an Action is optional. An Action is a recorded series of tasks performed on image. Actions can then be “played” or executed on other images. We will create Actions to resize and apply the sepia tone effect to our images.

Resizing Images

If the final pixel height & width are known, resizing images is easy to do with the Image Processor. However, we will resize images based on size percentage of the original image and not only that, but we will create three different sizes (75%, 50%, 25%) as well.

There are several ways to approach this:

  • Create an Action for each resize percentage, and then run separately in batch
  • Write a script that takes an input directory of images and then creates & saves the resized images to (preferably) a different directory
  • Create an Action which runs a script on an image that creates & saves the resized images to a specified directory. The Action is then executed in batch, with the input directory of images specified in the batch dialog

We will go with the last option, which is a combination of the first two options.

nyc skyline resizing illustration 04082016Original Image Scaled to 75%, 50% and 25%

Resizing One Image to Several Sizes

The following Javascript code, resizing-to-multiple.js, scales the current Photoshop image into three (3) different sizes, 75%, 50% & 25%, and saves them into the output directory, saveDir. This can be tested on one image by saving the script to a file (be sure to change the output directory to a valid directory on your system), select the script through File -> Scripts -> Browse… which will run it on the current image.

// Copyright (c) 2016, ytirahc, www.mobiledevtrek.com
// All rights reserved. Copyright holder cannot be held liable for any damages. 
// 
// Distributed under the Apache License (ASL). 
// http://www.apache.org/licenses/
// *****
// Description: This file is a script for Adobe Photoshop (tested with Photoshop CC 2015). 
// The current active image in Photoshop will be resized by the specified percentages
// in the array scaleFactor and will save those files to the specified directory, saveDir. 
//
// Usage: File -> Scripts -> Browse... to locate the script and execute it
// *****
 
var scaleFactor = [75, 50, 25];  // Scale factor as percentage of original image
var saveDir = "~/Documents/work/"; // Directory in which to save resized images
 
// Create resized image for all specified scale factors
for (var scaleFactorIndex in scaleFactor) 
{
	ResizeToScaleFactor(saveDir, scaleFactor[scaleFactorIndex])
}
 
// *****
// ResizeToScaleFactor
//
// Description: Resizes an image according to specified scale factor and saves it
//
// Parameters:
// 		inSaveDir: Directory in which to save resized image
//		inScaleFactor: Scale factor as a percentage in which to resize image
// *****
function ResizeToScaleFactor(inSaveDir, inScaleFactor) 
{
 
	var doc;  // Reference to the active document
	var duplicateDoc;  // Reference to a copy of the active document
	var imageName; // The name of the current document, without extension
	var saveFN; // The full file path and name of the image to be saved
	var saveFNOptions; // The save options
 
	// Reference to current, active document
	doc = app.activeDocument;
 
	// Duplicate document
	duplicateDoc = doc.duplicate();
 
	// Resize image according to specified scale factor
	duplicateDoc.resizeImage(UnitValue(inScaleFactor,"%"),null,null,ResampleMethod.BICUBIC);
 
	// Save the resized image as a jpg
	imageName = (doc.name).split(".")[0];
	saveFN = new File(inSaveDir + imageName + "_" + inScaleFactor + "percent.jpg" );
	saveFNOptions = new JPEGSaveOptions();
	saveFNOptions.embedColorProfile = true;
	saveFNOptions.formatOptions = FormatOptions.STANDARDBASELINE;
	saveFNOptions.matte = MatteType.NONE;
	saveFNOptions.quality = 9;
	duplicateDoc.saveAs(saveFN, saveFNOptions, true, Extension.LOWERCASE);
 
	// Close the duplicate image view without a save as dialog box
	duplicateDoc.close(SaveOptions.DONOTSAVECHANGES)
 
}

This code is also available here. Further information on the Photoshop JavaScript API can be found in the reference document.

Resizing Multiple Images to Several Sizes

To resize multiple images at once, we create an Action that will be executed in the Image Processor.

Creating An Action to Run the Script

  1. Open an image in Photoshop
  2. Open the Actions window, Windows -> Actions
  3. Create a new Action and name it “Resize & Save Images”
  4. Click Record
  5. Select the script to run it, File -> Scripts -> Browse…
  6. Click on the Stop button in the Actions window to halt the recording of actions

Now we have an Action that runs the script which scales an image to several sizes. We can use this Action in our batch processing. This step only has to be completed once as the Action is saved and reusable.

Running the Script on Multiple Images

  1. Open the Batch dialog, File -> Automate -> Batch
    • Play -> Action: Resizes & Save
    • Source: Folder
    • Source -> Choose: Select the directory where the input image files are located
    • Destination -> Save and Close
  2. Click OK

Images will flash on and off the screen as they are open and closed during processing.

Applying the Sepia Tone Effect

Applying the sepia tone effect to an image will give it an old, antique-ish photograph look. As a recap of the discussion of what the sepia tone effect algorithm entails, here is a list of steps to achieve it:

  1. Desaturate the image. The resulting image is greyscale.
  2. Apply a mild gaussian blur since most old photos are slightly blurry.
  3. Add a reddish brown (or dark orange) solid color layer above the photo layer, using the soft light blend mode.

As with resizing, we create an Action that we will run on a directory of images. No scripting required.

Sepia Tone EffectSepia Tone Effect Applied to Original Image

Creating An Action to Apply the Sepia Tone Effect

  1. Open an image in Photoshop
  2. Open the Actions window, Windows -> Actions
  3. Create a new Action and name it “Sepia Tone Effect”
  4. Click Record
  5. Convert the image to greyscale, Image -> Adjustments -> Desaturate
  6. Smooth it a tad, Filter -> Blur -> Gaussian Blur
    • Radius: 2
  7. Add a new layer, Layer -> New Fill Layer -> Solid Color
    • Mode: Soft Light [Click OK]
    • #: e2592a
  8. Halt the recording of actions by clicking on the Stop button in the Actions window

With the Action Sepia Tone Effect saved, we will apply it to a group of images using the Image Processor.

Apply the Sepia Tone Effect to Multiple Images

  1. Open the Image Processor dialog, File -> Scripts -> Image Processor
    • Select the images to process -> Select Folder: Choose the directory where the input image files are located
    • Select location to save processed images – > Select Folder: Choose the directory where the output files are to be saved
    • File Type: Click Save as JPEG
    • Preferences -> Run Action: Choose Sepia Tone Effect
  2. Click Run

Your processed images will be saved in the output directory you chose under a subdirectory called “JPEG”.

Coming Up …

Our mini-series exploring image batch processing will continue with GIMP.

Further Reading

  1. Adobe Photoshop Scripting References for Javascript, Applescript and VBScript
  2. Photoshop Help: Process a Batch of Files
  3. Photoshop Help: Creating Actions
  4. Creating Batch Actions

 

Leave a Reply

Your email address will not be published. Required fields are marked *