Auto Crop Advanced
Script for Adobe Photoshop
Latest update 6/14/2022, version 4.8
This script is an advanced version of the Photoshop script Auto Crop. Like the basic version, the script crops images using Photoshop’s Select Subject feature, and adds minimum margins to arrive at defined dimensions. But unlike the basic version, this advanced version gives the user independent control of all four margins, and adds the option to scale the result when the image does not reach the crop. Also this version adds the option of saving working PSD files if desired.
- Set margins independently
- Content-aware cropping, or scale to fit
- Layers cropped without deleting pixels
- Output to JPG, PNG, PSD, or TIF
- Save working PSD files
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. Or, for this advanced version, enable the option to save working PSD files, and any may be easily adjusted because all layers are cropped without deleting pixels.
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 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 (the default). When the option Include subfolders is enabled, the output subfolder structure matches the input subfolder structure. If Photoshop encounters non-image files that it cannot open, alerts are reported in the log file. For each image file found, the script crops the image and performs the options specified in the sections Resolution and Output.
Section 2: Size
Width and Height — set the width and height of the desired result.
Units — the measurement units of all values.
Margins — a distance from the subject that is the smallest margin once cropped. This advanced version allows margins to be set independently. This is used to crop the subject off-center, or for subjects that already reach an image edge but need margin around other sides. To keep from cropping an edge, set the margin to zero, and set other margins as desired. Some margins may be greater than values set depending on the cropped width and height, but the script attempts to keep margins no less than the values set. Some margins can end up slightly less, but not by a significant amount, only a few pixels at most.
Center — enable to make all margins match the value set for Left. This makes all margins equal, which results in the subject centered in the cropped area.
When image does not reach crop — when the dimensions and margins result in an image that does not reach one or more edges of the cropped area, use one or the other of the following options, or neither. If both are disabled, the missing area is empty. In all cases, an alert is added to the log file, or reported immediately if cropping the active image.
Use Content-Aware Fill — the script uses content-aware cropping to complete the missing image area.
Scale to fit — the image is scaled until it reaches the cropped edge, while trying to keep margins close to the desired values. Of course this alters margins, and the result can be considerably different from the values set, but no image area is missing.
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. When the input folder is selected in the Process section, the script sets this folder to the same plus the subfolder Cropped. To override, click the Folder button and select or create the desired folder to which cropped images are saved.
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 — 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. As Width and Height change, the suffix is updated to match. Having no suffix is allowed, and if desired, the suggested value may be cleared once sizes are set and before processing. However, 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.
Save working file (PSD) — saves a copy of the cropped image with all layers intact and cropped without deleting pixels. Click the Folder button to choose a location to store working PSD files.
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].
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.
License details included in download
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.