Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to export multiple images from image selection in psd

New Here ,
Aug 23, 2025 Aug 23, 2025

Hi everyone, hope you are all well!

 

I have been assigned to make layoutfiles from scanned contactsheets.

This process, if done manually, is very time consuming.

 

My current workflow is the following:

1. Open up contactsheet

2. Make selection of first image on contactsheet

3. Crop

4. Save as new file

5. Go one step back

6. Make selection of next image

7. Crop

8. Save as new file

And then just eat sleep repeat... I am currently doing this to a lot of contactsheet.

 

Does anyone have any sugestions to a better workflow?

 

I thought of a possible script where I could manually select all images in the ps file and then export all of these selections as individual files. Would this be possible?

I have a lot more to go so I am available if there are any questions to the process..

 

I hope anyone out there can help me.

 

Kind regards

Magny, dk

 

 

 

TOPICS
macOS
365
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 27, 2025 Aug 27, 2025

@Hans2552601244ud 

 

Here is a script to save each path defined area as a separate PSD file.

 

Here you can see that each path defines the area to crop and save as an image:

Photoshop_c4qv0iE0AV.png

 

Here are thumbs of the original file and the output:

Adobe_Bridge_p3ggPKKNnZ.png

 

/*
Save Multiple Path Defined Areas As Separate Files.jsx
Stephen Marsh
v1.0 - 27th August 2025: Initial release
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-export-multiple-images-from-image-selection-in-psd/td-p/15472805
*/

#target photos
...
Translate
Adobe
Community Expert ,
Aug 23, 2025 Aug 23, 2025

You can select each contact sheet image, then Ctrl/Cmd + Shift + J to a new layer, then go back to the original layer and reapeat. Then select all the required layers in the layers panel, right-click and then Export As, or use Export Layers to Files or other scripts to do the same.

 

For scripting, yes, the multiple selections can be converted to a path, then a script can then identify and work with each path separately. Here's an example that could be modified:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-do-i-seperate-subjects-into-diffe...

 

That being said, have you looked at fhe Crop & Straighten Photos command as an alternative (hopefully it will not try to straighten)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 24, 2025 Aug 24, 2025

Hi

Yes, I tried the Crop & Straighten Photos command and it is quite random. So that is not the answer..

 

Thank you for the tip on exporting the layers..

I think I will have to go with that solution as I have not been able to get the script to work properly.

 

Kind regards

Magny

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2025 Aug 24, 2025

That script was just an example of the general concept, it would require modifications for your particular case.

 

Can you provide one or more examples of the files that you're working on?

 

Is the layout consistent? Do all of the contact sheets have the same number of columns and rows and the same size thumbnails and orientation?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 24, 2025 Aug 24, 2025

Hi again

 

Yeah, I know. I tried modifying it myself but I am new to scripting and I havent gotten it to function yet.

I have attached a few examples..

No, unfurtunatly all contactsheets are different but with the same orientation and size.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 26, 2025 Aug 26, 2025

This isn't something that can be easily automated like the simpler coins scan example.

 

I can see this working as a semiautomatic process if you manually add a separate closed pen tool rectangle path on each image, then run a script to save each to file based on the paths. Or perhaps using a vector shape tool rectangle where each separate shape layer defines each image.

 

The crooked images would also be problematic, do you just crop without rotating or do these outliers need rotation?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2025 Aug 27, 2025
LATEST

@Hans2552601244ud 

 

Here is a script to save each path defined area as a separate PSD file.

 

Here you can see that each path defines the area to crop and save as an image:

Photoshop_c4qv0iE0AV.png

 

Here are thumbs of the original file and the output:

Adobe_Bridge_p3ggPKKNnZ.png

 

/*
Save Multiple Path Defined Areas As Separate Files.jsx
Stephen Marsh
v1.0 - 27th August 2025: Initial release
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-export-multiple-images-from-image-selection-in-psd/td-p/15472805
*/

#target photoshop

if (!documents.length) {
    alert("A document must be open to run this script!");
    exit();
}

var origDoc = app.activeDocument;
var normalPaths = [];

// Determine save folder: use doc path or default to desktop
var saveFolder;
if (origDoc.fullName) {
    saveFolder = origDoc.fullName.parent;
} else {
    saveFolder = Folder.desktop;
}

// Collect all normal paths
for (var i = 0; i < origDoc.pathItems.length; i++) {
    var path = origDoc.pathItems[i];
    if (path.kind == PathKind.NORMALPATH) {
        normalPaths.push(path);
    }
}

if (normalPaths.length === 0) {
    alert("Script aborted - no saved normal paths found!");
    exit();
}

var savedCount = 0;

// Loop through each path and process
for (var j = 0; j < normalPaths.length; j++) {
    var pathName = normalPaths[j].name;
    var tempDoc = origDoc.duplicate();
    tempDoc = app.activeDocument;
    try {
        tempDoc.pathItems.getByName(pathName).select();
    } catch (e) {
        alert("Could not select path: " + pathName);
        tempDoc.close(SaveOptions.DONOTSAVECHANGES);
        continue;
    }
    setSelectionToActivePath();
    crop();
    removeAllPaths(tempDoc);
    // Sequential numbering padded to 3 digits
    var seqNum = ("000" + (savedCount + 1)).slice(-3);
    var docBaseName = origDoc.name.replace(/\.[^\.]+$/, ""); // Remove extension
    var savePSDName = File(saveFolder + "/" + docBaseName + "_Image_" + seqNum + ".psd");
    // Save
    savePSD(savePSDName);
    savedCount++;
    tempDoc.close(SaveOptions.DONOTSAVECHANGES);
}

// End of script notification
app.beep();
alert("Script completed!" + "\n" + savedCount + " PSD files saved to:" + "\n" + saveFolder.fsName);


///// Functions /////

function setSelectionToActivePath() {
    try {
        var c2t = function (s) { return app.charIDToTypeID(s); };
        var s2t = function (s) { return app.stringIDToTypeID(s); };
        var descriptor = new ActionDescriptor();
        var reference = new ActionReference();
        var reference2 = new ActionReference();
        reference.putProperty(s2t("channel"), s2t("selection"));
        descriptor.putReference(c2t("null"), reference);
        reference2.putEnumerated(s2t("path"), s2t("ordinal"), s2t("targetEnum"));
        descriptor.putReference(s2t("to"), reference2);
        descriptor.putInteger(s2t("version"), 1);
        descriptor.putBoolean(s2t("vectorMaskParams"), true);
        executeAction(s2t("set"), descriptor, DialogModes.NO);
    } catch (e) {
        alert("Selection from path function error: " + e);
    }
}

function crop() {
    try {
        var s2t = function (s) { return app.stringIDToTypeID(s); };
        var descriptor = new ActionDescriptor();
        descriptor.putBoolean(s2t("delete"), true);
        executeAction(s2t("crop"), descriptor, DialogModes.NO);
    } catch (e) {
        alert("Crop function error: " + e);
    }
}

function removeAllPaths(doc) {
    try {
        for (var i = doc.pathItems.length - 1; i >= 0; i--) {
            doc.pathItems[i].remove();
        }
    } catch (e) {
        alert("Error removing paths: " + e);
    }
}

function savePSD(saveFile) {
    var psdSaveOptions = new PhotoshopSaveOptions();
    psdSaveOptions.embedColorProfile = true;
    psdSaveOptions.alphaChannels = true;
    psdSaveOptions.layers = true;
    psdSaveOptions.spotColors = true;
    activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}

 

  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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines