Script for Adobe Photoshop
Latest update 12/9/2023, version 6.1
The script crops images using Photoshop’s Select Subject feature, and adds a minimum margin to arrive at defined dimensions with the subject centered. The process may be performed on the active image, or a folder of images.
- Define image dimensions and minimum margin
- Content-aware cropping fills missing image area
- Resolution as-is or resample
- Append suffix identifying cropped size
- Output JPG, PNG, PSD, or TIF
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.
NOTE: after video production, features have been added in response to user feedback. 1. originally the script used Content-Aware fill always. The script has been updated so that Content-Aware fill is now an option that may be disabled. 2. the output folder no longer defaults to a subfolder “Cropped” under the input folder. Output to the input folder even when using a subfolder is no longer allowed. Select both the input and output folders, which are now remembered between runs of the script. 3. some of the interface has been altered slightly for better clarity. See instructions below for details.
How to use the script
The interface has five sections: Process, Size, Resolution, 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.
As of Photoshop version 23.5.0, Select Subject added the options Device (Quicker results) and Cloud (Detailed results). For most installations the default is Device, the only choice prior to version 23.5.0. The script uses whatever is the default method. To change the default method to the superior Cloud option, go to Preferences (Windows) or Settings (macOS), section Image Processing. Set the drop-down list Select Subject Processing to the desired default method.
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.
Folder — processes a folder of images. Click the Folder button to select the folder of images to crop.
Include subfolders — if enabled, images in subfolders are included. All subfolders in the input folder are created in the output folder so the subfolder structure is preserved.
Section 2: Size
Width and Height — set the width and height of the desired results. To the right of Width is a drop-down list of measurement units of used for all values.
Minimum margin — a distance from the subject that is the smallest margin once cropped. Some margins may be greater than this value depending on the cropped width and height, but the script attempts to keep margins no less than this value. Some margins can end up slightly less, but not by a significant amount, only a few pixels at most.
When image is less than crop — when the result of sizing the image does reach one or more edges of the cropping boundary, the user may choose to complete the missing image with content-aware fill by enabling the checkbox Use Content-Aware Fill.
If disabled, the missing image is transparent, unless the option Flatten is enabled, in which case the missing image is filled with white.
In all cases when the image is less than crop, an alert is added to the log file along with a description of the remedy, or if cropping the active image, the alert and remedy are reported immediately.
Section 3: Resolution
As-is (no interpolation; Pixels/Inch derived from new size) — the Pixels/Inch value changes as a result of cropping and resizing the image to the desired dimensions, but no image data is resampled. The pixels of the image after cropping are precisely the same pixels from before cropping/resizing, only less the pixels cropped away.
Resample to original Pixels/Inch — after the image is cropped, the image is resampled to the original Pixels/Inch value of the image before cropping/resizing. In the event this up-scales the resolution, an alert is added to the log file, or reported immediately if cropping the active image.
Resample — enter a value in pixels per inch. After the image is cropped, the resolution is adjusted to the specified value. In the event this up-scales the resolution, an alert is added to the log file, or reported immediately if cropping the active image.
Regarding “aspect ratio” versus size: the option As-is exists to satisfy users asking for cropping based on aspect ratio. This option changes the image size, but lets the resolution adjust to whatever value that size makes it, without removing any pixels beyond what cropping requires. The real size of any image is its pixel dimensions, not inches, millimeters, etc. Those are real-world units of measure for the benefit of humans. Without resampling pixel data, size expressed in inches (for example) simply sets how many pixels represent one inch. The point is, the As-is option makes specifying size identical to specifying aspect ratio. The only pixel data lost is the portion cropped away to arrive at the desired ratio of width to height.
Section 4: 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 JPEG, 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 — converts color to the selected profile prior to output.
The formats JPG, PSD, and TIF always embed color profiles. PNG does not embed color profiles.
Original file name + — a suffix of characters appended to each output file name. The characters entered must be legal to use in file names. Any illegal characters are automatically removed. As Width and Height change, the suffix is updated to match. Having no suffix is allowed, in which case output file names exactly match input file names.
When files are output, any existing files of the same name in the output folder are replaced without alert.
Section 5: 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].
When settings are saved, there is also the option to include Input folder and/or Output folder.
Each time the script is launched, the input and output folders are restored to the last location used. To override these defaults, enable the options to include Input folder and/or Output folder. When the saved settings are loaded, the input folder and/or output folder are restored to the values saved.
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.
Change log: auto-crop.txt
For help installing scripts, see How to Install and Use Scripts in Adobe Creative Cloud Applications.
IMPORTANT: scripts are developed for the latest Adobe Creative Cloud applications. Many scripts work in CC 2018 and later, even some as far back as CS6, but may not perform as expected, or run at all, when used in versions prior to 2018. Photoshop features Select Subject and Preserve Details 2.0 definitely fail prior to CC 2018 (version 19) as the features do not exist in earlier versions. For best results use the latest versions of Adobe Creative Cloud applications.
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.
IMPORTANT: fees paid for software products are the purchase of a non-exclusive license to use the software product and do not grant the purchaser any degree of ownership of the software code. Author of the intellectual property and copyright holder William Campbell retains 100% ownership of all code used in all software products regardless of the inspiration for the software product design or functionality.