Skip to main content
Mike McCollister
Participating Frequently
June 2, 2026
Answered

Photoshop Action Help for Sizing Photos Down to Specific Sizes

  • June 2, 2026
  • 3 replies
  • 67 views

I have a large number of photos that were scanned from negatives years ago. Ideally, they would be a perfect 3x2 or 2x3 aspect ratio but that is not the case. I am looking to size them for the web using Photoshop. I can do this manually but I am looking to create an action to do such.

This is what I typically do.

  1. Size the longest edge to be 1200px.

  2. If shortest edge is >= 800px, trim the canvas down so that the image is now 1200x800 (or 800x1200),

  3. Else if the shortest edge < 800px, size the image so that the shortest edge is 800px and trim the canvas so that the image is 1200x800 (or 800x1200).

  4. Save the file as "<Original Name> (Full).jpg" in a different folder.

  5. Size the image down to 266x400 (or 400x266 if landscape).

  6. Save the file as "<Original Name> (Thumb).jpg" in a different folder.

I'm having problems creating the action, specifically with steps 2 & 3. Any hints or pointers for that?

    Correct answer Stephen Marsh

    The following script can be recorded into an action for File > Automate > Batch or bulk running via Image Processor or Image Processor Pro scripts for the Action Steps 2 & 3:

     

    #target photoshop

    if (app.documents.length > 0) {

    var doc = app.activeDocument;
    var w = doc.width.as("px");
    var h = doc.height.as("px");
    var targetW;
    var targetH;

    // Determine output orientation from original image
    if (w >= h) {
    targetW = 1200;
    targetH = 800;
    } else {
    targetW = 800;
    targetH = 1200;
    }

    // Calculate scale factor required to completely cover target
    var scaleFactor = Math.max(targetW / w, targetH / h);
    var newW = Math.round(w * scaleFactor);
    var newH = Math.round(h * scaleFactor);

    // Resize image proportionally
    var resampleMethod;
    if (scaleFactor > 1) {
    resampleMethod = ResampleMethod.BICUBICSMOOTHER; // upscale
    } else {
    resampleMethod = ResampleMethod.BICUBICSHARPER; // downscale
    }
    doc.resizeImage(UnitValue(newW, "px"), UnitValue(newH, "px"), null, resampleMethod);

    // Crop or extend canvas to final dimensions
    doc.resizeCanvas(UnitValue(targetW, "px"), UnitValue(targetH, "px"), AnchorPosition.MIDDLECENTER);

    /*
    alert(
    "Original: " + w + " x " + h +
    "\nResized: " + newW + " x " + newH +
    "\nFinal Canvas: " + targetW + " x " + targetH
    );
    */

    } else {
    // alert("No document open.");
    }

     

    1. Copy the code text to the clipboard
    2. Open a new blank file in a plain-text editor (not in a word processor)
    3. Paste the code in
    4. Save as a plain text format file – .txt
    5. Rename the saved file extension from .txt to .jsx
    6. Install or browse to the .jsx file to run (see below):

    https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

    3 replies

    Stephen Marsh
    Community Expert
    Community Expert
    June 2, 2026

    Another option could be to record the following script into an action, which auto crops to the nearest aspect ratio (you said that they are close to 2:3 or 3:2)... Followed by a recording of fit image to 1200 x 1200 px which should then make the short edge 800 px by default.

     

     

    Stephen Marsh
    Community Expert
    Stephen MarshCommunity ExpertCorrect answer
    Community Expert
    June 2, 2026

    The following script can be recorded into an action for File > Automate > Batch or bulk running via Image Processor or Image Processor Pro scripts for the Action Steps 2 & 3:

     

    #target photoshop

    if (app.documents.length > 0) {

    var doc = app.activeDocument;
    var w = doc.width.as("px");
    var h = doc.height.as("px");
    var targetW;
    var targetH;

    // Determine output orientation from original image
    if (w >= h) {
    targetW = 1200;
    targetH = 800;
    } else {
    targetW = 800;
    targetH = 1200;
    }

    // Calculate scale factor required to completely cover target
    var scaleFactor = Math.max(targetW / w, targetH / h);
    var newW = Math.round(w * scaleFactor);
    var newH = Math.round(h * scaleFactor);

    // Resize image proportionally
    var resampleMethod;
    if (scaleFactor > 1) {
    resampleMethod = ResampleMethod.BICUBICSMOOTHER; // upscale
    } else {
    resampleMethod = ResampleMethod.BICUBICSHARPER; // downscale
    }
    doc.resizeImage(UnitValue(newW, "px"), UnitValue(newH, "px"), null, resampleMethod);

    // Crop or extend canvas to final dimensions
    doc.resizeCanvas(UnitValue(targetW, "px"), UnitValue(targetH, "px"), AnchorPosition.MIDDLECENTER);

    /*
    alert(
    "Original: " + w + " x " + h +
    "\nResized: " + newW + " x " + newH +
    "\nFinal Canvas: " + targetW + " x " + targetH
    );
    */

    } else {
    // alert("No document open.");
    }

     

    1. Copy the code text to the clipboard
    2. Open a new blank file in a plain-text editor (not in a word processor)
    3. Paste the code in
    4. Save as a plain text format file – .txt
    5. Rename the saved file extension from .txt to .jsx
    6. Install or browse to the .jsx file to run (see below):

    https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

    Mike McCollister
    Participating Frequently
    June 2, 2026

    Thank you so much. I had no idea that Photoshop could handle JavaScript. I’ll give that a try in a few days and see how it works.

    Stephen Marsh
    Community Expert
    Community Expert
    June 2, 2026

    Action step 1: 

     

    Always work on copies of the originals (check your disk space).

     

    You can record File > Automate > Fit Image into the action, with a width of 1200 px and a height of 1200 px:

     

     

    This will make the longest edge 1200 px with the shortest edge proportional, regardless of portrait or landscape orientation.

     

    Action Steps 2 & 3:

     

    Require conditional processing, unfortunately, a conditional action can't do this based on canvas px size:

     

     

    Therefore, a conditional script will be needed to handle the automated processing. A new script will be required for your use case.

     

    https://snipit.io/public/collections/22660/22660

     

    https://prepression.blogspot.com/2022/11/photoshop-action-helper-scripts.html