Crop To Template

Script for Adobe Photoshop
Latest update 9/28/2022, version 1.4

Crop images to fit inside guides of a selected template document.

  • Crop current image or folder of images
  • Choice of vertical position when subject is wide
  • Option to use content-aware fill
  • Append suffix to output file names
  • Output to JPG, PNG, PSD, or TIF
  • Save and restore all settings

IMPORTANT: the script depends on the Photoshop feature Select Subject that was introduced in Photoshop CC 2018 (version 19). Earlier versions of Photoshop will not run this script correctly. For best results use the latest version of Photoshop as the Select Subject feature has improved greatly in recent years.

Download
FREE 30 DAY TRIAL

Single-user perpetual license

Before using the script

The script requires a template document that images are fit into. This document must be open before running the script, and is selected in the script interface. The pixel dimensions of the template document determine the final dimensions of each cropped image. Ideally the template document has four guides, two in each direction: one each top and bottom, and one each left and right. These guides define the desired margins, and the area inside the guides is where images will be scaled and positioned to fit. When the subject is tall, it is centered left to right. When wide, the user may choose vertical position top, middle, or bottom. Guides may be absent in either direction, in which case that margin is zero. A single guide in either direction does not work and reports “Template has improper guides.”

Example template document with guides to indicate margins.

The script reads the guides and considers the highest and lowest to be top and bottom, and the guides most left and most right to be the side boundaries of the target area. Additional guides between the outermost guides are ignored.

How to use the script

The interface has four sections: Process, Options, Output, and Settings. Set options as desired and click OK to begin. If processing the active image, any errors or concerns are reported immediately. If processing a folder, a progress bar is displayed. To cancel processing, press the ESC key. Otherwise, when complete, the number of images processed is reported. If any concerns are encountered, a log file is written to the output folder, and the user is notified.

The script depends on the accuracy of Photoshop’s Select Subject feature, which works well in most cases, but isn’t perfect 100% of the time. At a minimum, the user should open Bridge and scan through thumbnails of cropped images to ensure the results are satisfactory. For any images that crop improperly, open in Photoshop and crop manually.

Section 1: Process

Active image — processes the image that is currently open and the top-most window if multiple images are open. When this option is selected, the section Output is disabled. It is for the user to perform additional transformations if needed and Save As the cropped version of the image in the desired format. A revised file name should be used to preserve the original un-cropped version of the image. If there is only a single image open, it can only be the template, so this option is disabled and processing a folder (next) is enabled instead.

Folder — Processes a folder of images. Click the button Folder to select the desired input folder. If the option Include subfolders is checked, all folders in the selected folder are also processed, with the exception of the folder selected in the Output section, if it is below the input folder. When the option Include subfolders is enabled, the subfolder structure is created in the output folder. If Photoshop cannot open an image or other problems occur, alerts are reported in the log file. For each image file found, the script crops the image to fit into the template document.

Section 2: Options

Template — from the list of open documents, choose the desired template document.

Wide subject vertical position — when the width of the subject is more than its height, this option determines the vertical position of the subject within the guides. Choice are Top, Middle, and Bottom. When subject height is greater than its width, the subject reaches the top and bottom guides and is centered left to right, in which case this option has no effect.

When image is less than crop — when the cropping boundary exceeds the original image, the user may choose to either fill the missing area with the current background color, or use content-aware fill to complete the missing image. In either case, the condition is reported in the log file, or reported immediately if cropping the active image.

Section 3: Output

Folder — the location to which cropped images are saved. Click the button Folder and navigate to the desired location.

Format — choose from four common file formats: JPG, PNG, PSD, or TIF.

Flatten — reduces layers to a single background layer. If disabled, layers remain, but understand that some formats and situations always flatten the image. For example, output to JPG, because the format does not support layers. The PNG format is always converted to sRGB web standard, and this can also trigger flattening. As well, images converted from RGB to CMYK may flatten to preserve the effect of adjustment layers, which cannot convert from one color space to another.

Quality (JPG format only) — valid range is from 0 to 12. 0 is extreme compression resulting in low quality. 12 is light compression that is virtually indistinguishable from the original, the highest possible quality, which of course, results in the largest file size. 10 to 12 is recommended for print or other high-quality reproduction. For web images, 5 to 8 is an acceptable range.

Convert to profile — the cropped image is converted to the specified profile. Note that PNG always converts to sRGB web standard. All other formats embed either the original color profile or the profile to which the image is converted.

Original file name + — a suffix of characters appended to each cropped image file name. The characters entered must be legal to use in file names. Having no suffix is allowed, but note that without a suffix, output to the input folder is not allowed to prevent overwriting input files.

When cropped images are output, any existing cropped images of the same name are replaced without alert.

Section 4: Settings

The current options may be saved and restored later. Select from the Load drop-down list to choose saved settings, and the current options are updated. Click the Delete button, and the saved settings selected in the Load drop-down list are permanently removed. Click the Save button, provide a name for the settings, and the current options are preserved. If the name already exists, the user may choose to replace the saved settings. Or click the checkbox Replace settings, and choose the settings to replace.

The script provides default saved settings named [Default]. These settings cannot be deleted but may be updated to the current values. Save settings, click the checkbox Replace settings, and choose [Default].

Available color profiles

For the option Convert to profile, the list of profiles from which to choose is compiled by searching known locations in the system for .icc/.icm files and extracting the profile name. This occurs each time the script is launched. The list should include most of the same profiles Photoshop displays in dialogs such as Color Settings, but it doesn’t match exactly. If a needed profile does not appear in the list, add the profile to a location both Photoshop and the script look for profiles (below), and relaunch the script.

macOS

:Library:ColorSync:Profiles

Windows

\Windows\System32\spool\drivers\color

Download
FREE 30 DAY TRIAL

Single-user perpetual license

For help installing scripts, see How to Install and Use Scripts in Adobe Creative Cloud Applications.

Also available for hire to program custom solutions. Contact William for more information.

IMPORTANT: by downloading any of the scripts on this page you agree that the software is provided without any warranty, express or implied. USE AT YOUR OWN RISK. Always make backups of important data.